4.0.4-alt95.M41.18

- package.c (readPackageHeaders): Use posix_fadvise(2) to disable readahead.
  When scanning a large number of packages (with e.g. rpmquery), readahead
  might cause negative effects on the buffer cache.
This commit is contained in:
Alexey Tourbin 2009-05-10 23:41:33 +04:00
commit 9e87611786
2 changed files with 33 additions and 8 deletions

View File

@ -137,7 +137,7 @@ Header headerRegenSigHeader(const Header h)
* @param hdrPtr address of header (or NULL)
* @return rpmRC return code
*/
static rpmRC readPackageHeaders(FD_t fd,
static rpmRC do_readPackageHeaders(FD_t fd,
/*@null@*/ /*@out@*/ struct rpmlead * leadPtr,
/*@null@*/ /*@out@*/ Header * sigs,
/*@null@*/ /*@out@*/ Header * hdrPtr)
@ -148,17 +148,11 @@ static rpmRC readPackageHeaders(FD_t fd,
Header * hdr = NULL;
struct rpmlead * lead;
char * defaultPrefix;
struct stat sb;
rpmRC rc;
hdr = hdrPtr ? hdrPtr : &hdrBlock;
lead = leadPtr ? leadPtr : &leadBlock;
memset(&sb, 0, sizeof(sb));
(void) fstat(Fileno(fd), &sb);
/* if fd points to a socket, pipe, etc, sb.st_size is *always* zero */
if (S_ISREG(sb.st_mode) && sb.st_size < sizeof(*lead)) return 1;
if (readLead(fd, lead))
return RPMRC_FAIL;
@ -243,6 +237,32 @@ static rpmRC readPackageHeaders(FD_t fd,
return RPMRC_OK;
}
static rpmRC readPackageHeaders(FD_t fd,
/*@null@*/ /*@out@*/ struct rpmlead * leadPtr,
/*@null@*/ /*@out@*/ Header * sigs,
/*@null@*/ /*@out@*/ Header * hdrPtr)
/*@modifies fd, *leadPtr, *sigs, *hdrPtr @*/
{
struct stat sb;
int readahead_off = 0;
/* if fd points to a socket, pipe, etc, sb.st_size is *always* zero */
if (fstat(Fileno(fd), &sb) == 0 && S_ISREG(sb.st_mode)) {
if (sb.st_size < sizeof(struct rpmlead))
return 1;
/* Typical header size is 4-16K, and default readahead is 128K.
* When scanning a large number of packages (with e.g. rpmquery),
* readahead might cause negative effects on the buffer cache. */
if (sb.st_size > /* page size */ 4096)
if (posix_fadvise(Fileno(fd), 0, 0, POSIX_FADV_RANDOM) == 0)
readahead_off = 1;
}
rpmRC rc = do_readPackageHeaders(fd, leadPtr, sigs, hdrPtr);
/* re-enable readahead for cpio */
if (readahead_off)
posix_fadvise(Fileno(fd), 0, 0, POSIX_FADV_NORMAL);
return rc;
}
rpmRC rpmReadPackageInfo(FD_t fd, Header * sigp, Header * hdrp)
{
rpmRC rc = readPackageHeaders(fd, NULL, sigp, hdrp);

View File

@ -4,7 +4,7 @@
Name: %rpm_name
Version: %rpm_version
Release: alt95.M41.17
Release: alt95.M41.18
%define ifdef() %if %{expand:%%{?%{1}:1}%%{!?%{1}:0}}
%define get_dep() %(rpm -q --qf '%%{NAME} >= %%|SERIAL?{%%{SERIAL}:}|%%{VERSION}-%%{RELEASE}' %1 2>/dev/null || echo '%1 >= unknown')
@ -528,6 +528,11 @@ fi
%endif #with contrib
%changelog
* Sun May 10 2009 Alexey Tourbin <at@altlinux.ru> 4.0.4-alt95.M41.18
- package.c (readPackageHeaders): Use posix_fadvise(2) to disable readahead.
When scanning a large number of packages (with e.g. rpmquery), readahead
might cause negative effects on the buffer cache.
* Thu Apr 23 2009 Alexey Tourbin <at@altlinux.ru> 4.0.4-alt95.M41.17
- rpmdb: Removed db1 support.
- db3.c (db3close): Backported fix for double close (RH#138589).