Skip to content

Commit

Permalink
{Server] Replace all occurrences of memalign() with posix_memalign().
Browse files Browse the repository at this point in the history
  • Loading branch information
abh3 committed Oct 16, 2020
1 parent 5794f93 commit 9ec715b
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/Xrd/XrdBuffXL.cc
Expand Up @@ -134,7 +134,7 @@ XrdBuffer *XrdBuffXL::Obtain(int sz)

// Allocate a chunk of aligned memory
//
if (!(memp = static_cast<char *>(memalign(pagsz, buffSz)))) return 0;
if (posix_memalign((void **)&memp, pagsz, buffSz)) return 0;

// Wrap the memory with a buffer object
//
Expand Down
2 changes: 1 addition & 1 deletion src/Xrd/XrdBuffer.cc
Expand Up @@ -175,7 +175,7 @@ XrdBuffer *XrdBuffManager::Obtain(int sz)
// Allocate a chunk of aligned memory
//
pk = (mk < pagsz ? mk : pagsz);
if (!(memp = static_cast<char *>(memalign(pk, mk)))) return 0;
if (posix_memalign((void **)&memp, pk, mk)) return 0;

// Wrap the memory with a buffer object
//
Expand Down
3 changes: 2 additions & 1 deletion src/Xrd/XrdPollE.icc
Expand Up @@ -33,6 +33,7 @@
#endif

#include <fcntl.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/epoll.h>
Expand Down Expand Up @@ -63,7 +64,7 @@ XrdPoll *XrdPoll::newPoller(int pollid, int maxfd)
//
bytes = maxfd * sizeof(struct epoll_event);
alignment = (bytes < pagsz ? 1024 : pagsz);
if (!(pp = (struct epoll_event *)memalign(alignment, bytes)))
if (posix_memalign((void **)&pp, alignment, bytes))
{Log.Emsg("Poll", ENOMEM, "create poll table");
close(pfd);
return 0;
Expand Down
3 changes: 2 additions & 1 deletion src/Xrd/XrdPollPoll.icc
Expand Up @@ -32,6 +32,7 @@
#endif

#include <signal.h>
#include <stdlib.h>

#include "Xrd/XrdLinkCtl.hh"
#include "Xrd/XrdPollPoll.hh"
Expand All @@ -50,7 +51,7 @@ XrdPoll *XrdPoll::newPoller(int pollid, int maxfd)
//
bytes = maxfd * sizeof(struct pollfd);
alignment = (bytes < pagsz ? 1024 : pagsz);
if (!(pp = (struct pollfd *)memalign(alignment, bytes)))
if (posix_memalign((void **)&pp, alignment, bytes))
{Log.Emsg("Poll", ENOMEM, "create poll table");
return 0;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Xrd/XrdStats.cc
Expand Up @@ -31,6 +31,7 @@
#include <malloc.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/resource.h>

Expand Down Expand Up @@ -195,7 +196,7 @@ const char *XrdStats::GenStats(int &rsz, int opts) // statsMutex must be locked!
{blen = InfoStats(0,0) + BuffPool->Stats(0,0) + XrdLink::Stats(0,0)
+ ProcStats(0,0) + XrdSched->Stats(0,0) + XrdPoll::Stats(0,0)
+ XrdProtLoad::Statistics(0,0) + ovrhed + Hlen;
buff = (char *)memalign(getpagesize(), blen+256);
if (posix_memalign((void **)&buff, getpagesize(), blen+256)) buff = 0;
if (!(bp = buff)) {rsz = snulsz; return snul;}
}
bl = blen;
Expand Down
2 changes: 1 addition & 1 deletion src/XrdNet/XrdNetBuffer.cc
Expand Up @@ -83,7 +83,7 @@ XrdNetBuffer *XrdNetBufferQ::Alloc()
//
if ((bp = BuffStack.Pop())) numbuff--;
else if ((bp = new XrdNetBuffer(this))
&& !(bp->data = (char *)memalign(alignit, size)))
&& posix_memalign((void **)&(bp->data), alignit, size))
{delete bp; bp = 0;}

// Unlock the data area
Expand Down
4 changes: 2 additions & 2 deletions src/XrdOuc/XrdOucBuffer.hh
Expand Up @@ -248,8 +248,8 @@ inline void SetLen(int dataL, int dataO=0) {dlen = dataL; doff = dataO;}
//! the Clone(), Highjack() and Resize() methods will always fail. However,
//! all the other methods will work in the expected way.
//!
//! @param buff - pointer to a storage area obtained via malloc and its
//! relatives (e.g. memalign). It will be released via free().
//! @param buff - pointer to a storage area obtained via posix_memalign()
//! and it will be released via free().
//! @param blen - the size of the buffer as well as the data length.
//! Use SetLen() to set a new data length if it differs.
//-----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/XrdSciTokens/XrdSciTokens
Submodule XrdSciTokens updated 1 files
+1 −2 CMakeLists.txt
2 changes: 1 addition & 1 deletion src/XrdSys/XrdSysIOEventsPollPort.icc
Expand Up @@ -164,7 +164,7 @@ int XrdSys::IOEvents::PollPort::AllocMem(void **memP, int slots)
//
bytes = slots * sizeof(port_event_t);
alignment = (bytes < pagsz ? 1024 : pagsz);
if (!(*memP = memalign(alignment, bytes))) return ENOMEM;
if (posix_memalign(memP, alignment, bytes)) return ENOMEM;
memset(*memP, 0, bytes);
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/XrdSys/XrdSysLogging.cc
Expand Up @@ -107,7 +107,7 @@ bool XrdSysLogging::Configure(XrdSysLogger &logr, Parms &parms)
// Allocate a log buffer
//
int bsz = (parms.bufsz < 0 ? 65536 : parms.bufsz);
rc = posix_memalign(reinterpret_cast<void**>(&buffOrg), getpagesize(), bsz);
rc = posix_memalign((void **)&buffOrg, getpagesize(), bsz);
if (rc != 0 || !buffOrg) return EMsg(logr, "Unable to allocate log buffer!\n");

buffBeg = buffOrg + buffOvhd;
Expand Down
8 changes: 3 additions & 5 deletions src/XrdSys/XrdSysPlatform.hh
Expand Up @@ -62,7 +62,9 @@
#include <sys/types.h>
#endif

#ifdef __solaris__
// The following provides historical support for Solaris 5.10.x
//
#if defined(__solaris__) && defined(__SunOS_5_10)
#define posix_memalign(memp, algn, sz) \
((*memp = memalign(algn, sz)) ? 0 : ENOMEM)
#define __USE_LEGACY_PROTOTYPES__ 1
Expand Down Expand Up @@ -121,9 +123,6 @@ typedef off_t offset_t;
#define POLLWRNORM 0
#endif
#define O_LARGEFILE 0
#define memalign(pgsz,amt) valloc(amt)
#define posix_memalign(memp, algn, sz) \
((*memp = memalign(algn, sz)) ? 0 : ENOMEM)
#define SHMDT_t void *
#ifndef EDEADLOCK
#define EDEADLOCK EDEADLK
Expand All @@ -133,7 +132,6 @@ typedef off_t offset_t;
#ifdef __FreeBSD__
#define O_LARGEFILE 0
typedef off_t off64_t;
#define memalign(pgsz,amt) valloc(amt)
#endif

// Only sparc platforms have structure alignment problems w/ optimization
Expand Down
7 changes: 4 additions & 3 deletions src/XrdXrootd/XrdXrootdGSReal.cc
Expand Up @@ -30,6 +30,7 @@

#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/uio.h>

Expand Down Expand Up @@ -72,7 +73,7 @@ XrdXrootdGSReal::XrdXrootdGSReal(const XrdXrootdGSReal::GSParms &gsParms,
static const int minSZ = 1024;
static const int dflSZ = 1024*32;
static const int maxSZ = 1024*64;
int flsT, maxL, hdrLen, pgSZ = getpagesize();
int flsT, maxL, hdrLen;

// Do common initialization
//
Expand All @@ -89,8 +90,8 @@ XrdXrootdGSReal::XrdXrootdGSReal(const XrdXrootdGSReal::GSParms &gsParms,

// Allocate the UDP buffer
//
if (maxL < pgSZ) udpBuffer = (char *)memalign(maxL, maxL);
else udpBuffer = (char *)memalign(pgSZ, maxL);
int align = (maxL < getpagesize() ? maxL : getpagesize());
if (posix_memalign((void **)&udpBuffer, align, maxL)) {aOK = false; return;}

// Setup the header as needed
//
Expand Down
5 changes: 2 additions & 3 deletions src/XrdXrootd/XrdXrootdMonitor.cc
Expand Up @@ -339,7 +339,7 @@ XrdXrootdMonitor::XrdXrootdMonitor()

// Allocate a monitor buffer
//
if (!(monBuff = (XrdXrootdMonBuff *)memalign(getpagesize(), monBlen)))
if (posix_memalign((void **)&monBuff, getpagesize(), monBlen))
eDest->Emsg("Monitor", "Unable to allocate monitor buffer.");
else {nextEnt = 1;
setTMark(monBuff, 0, localWindow);
Expand Down Expand Up @@ -745,8 +745,7 @@ int XrdXrootdMonitor::Init()
// Allocate as many redirection monitors as requested
//
for (i = 0; i < rdrNum; i++)
{rdrMon[i].Buff = (XrdXrootdMonBurr *)memalign(getpagesize(),monRlen);
if (!rdrMon[i].Buff)
{if (posix_memalign((void **)&rdrMon[i].Buff, getpagesize(),monRlen))
{eDest->Emsg("Monitor", "Unable to allocate monitor rdr buffer.");
return 0;
}
Expand Down

0 comments on commit 9ec715b

Please sign in to comment.