From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4839 invoked by alias); 3 Oct 2002 21:40:10 -0000 Mailing-List: contact libc-hacker-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sources.redhat.com Received: (qmail 4823 invoked from network); 3 Oct 2002 21:40:09 -0000 Received: from unknown (HELO deimos.hpl.hp.com) (192.6.19.190) by sources.redhat.com with SMTP; 3 Oct 2002 21:40:09 -0000 Received: from hplms2.hpl.hp.com (hplms2.hpl.hp.com [15.0.152.33]) by deimos.hpl.hp.com (8.9.3 (PHNE_24419)/HPL-PA Relay) with ESMTP id OAA17325; Thu, 3 Oct 2002 14:40:08 -0700 (PDT) Received: from napali.hpl.hp.com (napali.hpl.hp.com [15.4.89.123]) by hplms2.hpl.hp.com (8.10.2/8.10.2 HPL-PA Hub) with ESMTP id g93Le7B15175; Thu, 3 Oct 2002 14:40:07 -0700 (PDT) Received: from napali.hpl.hp.com (napali [127.0.0.1]) by napali.hpl.hp.com (8.12.3/8.12.3/Debian -4) with ESMTP id g93Le7HW000760; Thu, 3 Oct 2002 14:40:07 -0700 Received: (from davidm@localhost) by napali.hpl.hp.com (8.12.3/8.12.3/Debian -4) id g93Le39D000756; Thu, 3 Oct 2002 14:40:03 -0700 Resent-From: David Mosberger Resent-Message-ID: <15772.47411.167407.729409@napali.hpl.hp.com> Resent-Date: Thu, 3 Oct 2002 14:40:03 -0700 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15772.40078.639559.955906@napali.hpl.hp.com> In-Reply-To: <3D9BEF31.7050101@redhat.com> References: <200210030703.g9373MV6020484@napali.hpl.hp.com> <3D9BEF31.7050101@redhat.com> From: David Mosberger To: Ulrich Drepper Cc: davidm@hpl.hp.com, libc-hacker@sources.redhat.com Subject: Re: [patch] add alloc_pages/free_pages support Date: Thu, 03 Oct 2002 14:44:00 -0000 Reply-To: davidm@hpl.hp.com X-SW-Source: 2002-10/txt/msg00022.txt.bz2 Message-ID: <20021003144400.TLPp8sSR6jRohhA3fLQZeearjnicyoXvqvCGyHgWCV0@z> >>>>> On Thu, 03 Oct 2002 00:18:09 -0700, Ulrich Drepper said: Uli> - - no copyright comment Uli> - - parameters have no leading __ Uli> - - no comment for the functions explaining the purpose and the Uli> parameters OK, how about the attached patch? It takes care of the above comments and also adds a gethugepage() function. --david 2002-10-03 David Mosberger * sysdeps/unix/sysv/linux/getsysstats.c (get_meminfo): New function. (phys_pages_info): Implementing on the basis of get_meminfo(). (__gethugepagesize): New function. * sysdeps/unix/sysv/linux/Versions: Mention gethugepagesize(). 2002-10-02 David Mosberger * sysdeps/unix/sysv/linux/Makefile (sysdep_headers): Mention sys/hugepage.h. * sysdeps/unix/sysv/linux/syscalls.list: Make alloc_hugepages and free_hugepages weak symbols. * sysdeps/unix/sysv/linux/Versions: Mention alloc_hugepages and free_hugepages. 2002-10-01 Rohit Seth , David Mosberger * sysdeps/unix/sysv/linux/syscalls.list: Add alloc_hugepages and free_hugepages. * sysdeps/unix/sysv/linux/sys/hugepage.h: New file. 2002-10-02 David Mosberger * sysdeps/ia64/bzero.S: Rewritten by Sverre Jarp to tune for Itanium 2 (and Itanium). Fix unwind directives and make it fit in 80 columns. * sysdeps/ia64/memset.S: Ditto. * sysdeps/ia64/memcpy.S: Ditto. Move jump table to .rodata section. Index: sysdeps/unix/sysv/linux/Makefile =================================================================== RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/Makefile,v retrieving revision 1.121 diff -u -r1.121 Makefile --- sysdeps/unix/sysv/linux/sysdeps/unix/sysv/linux/Makefile 15 Sep 2002 02:30:28 -0000 1.121 +++ sysdeps/unix/sysv/linux/sysdeps/unix/sysv/linux/Makefile 3 Oct 2002 19:34:12 -0000 @@ -20,7 +20,7 @@ sys/kd.h sys/soundcard.h sys/vt.h \ sys/quota.h sys/fsuid.h \ scsi/sg.h scsi/scsi.h scsi/scsi_ioctl.h sys/pci.h \ - sys/ultrasound.h sys/raw.h sys/personality.h + sys/ultrasound.h sys/raw.h sys/personality.h sys/hugepage.h install-others += $(inst_includedir)/bits/syscall.h Index: sysdeps/unix/sysv/linux/Versions =================================================================== RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/Versions,v retrieving revision 1.18 diff -u -r1.18 Versions --- sysdeps/unix/sysv/linux/sysdeps/unix/sysv/linux/Versions 30 Aug 2002 01:30:55 -0000 1.18 +++ sysdeps/unix/sysv/linux/sysdeps/unix/sysv/linux/Versions 3 Oct 2002 19:34:12 -0000 @@ -102,6 +102,10 @@ # r* readahead; + gethugepagesize; + alloc_hugepages; + free_hugepages; + #errlist-compat 126 _sys_errlist; sys_errlist; _sys_nerr; sys_nerr; } Index: sysdeps/unix/sysv/linux/getsysstats.c =================================================================== RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/getsysstats.c,v retrieving revision 1.22 diff -u -r1.22 getsysstats.c --- sysdeps/unix/sysv/linux/sysdeps/unix/sysv/linux/getsysstats.c 21 Sep 2002 05:26:12 -0000 1.22 +++ sysdeps/unix/sysv/linux/sysdeps/unix/sysv/linux/getsysstats.c 3 Oct 2002 19:34:12 -0000 @@ -230,11 +230,8 @@ #endif weak_alias (__get_nprocs_conf, get_nprocs_conf) -/* General function to get information about memory status from proc - filesystem. */ static long int -internal_function -phys_pages_info (const char *format) +get_meminfo (const char *format) { FILE *fp; char buffer[8192]; @@ -264,7 +261,7 @@ while (fgets_unlocked (buffer, sizeof buffer, fp) != NULL) if (sscanf (buffer, format, &result) == 1) { - result /= (__getpagesize () / 1024); + result /= 1024; break; } @@ -279,6 +276,20 @@ return result; } +/* General function to get information about memory status from proc + filesystem. */ +static long int +internal_function +phys_pages_info (const char *format) +{ + long int result = get_meminfo (format); + + if (result != -1) + result /= __getpagesize (); + + return result; +} + /* Return the number of pages of physical memory in the system. There is currently (as of version 2.0.21) no system call to determine the @@ -320,6 +331,12 @@ } weak_alias (__get_avphys_pages, get_avphys_pages) +long int +__gethugepagesize () +{ + return get_meminfo ("Hugepagesize: %lu kB"); +} +weak_alias (__gethugepagesize, gethugepagesize); static void free_mem (void) Index: sysdeps/unix/sysv/linux/syscalls.list =================================================================== RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/syscalls.list,v retrieving revision 1.94 diff -u -r1.94 syscalls.list --- sysdeps/unix/sysv/linux/sysdeps/unix/sysv/linux/syscalls.list 15 Aug 2002 08:25:16 -0000 1.94 +++ sysdeps/unix/sysv/linux/sysdeps/unix/sysv/linux/syscalls.list 3 Oct 2002 19:34:12 -0000 @@ -80,3 +80,5 @@ lremovexattr EXTRA lremovexattr i:ss lremovexattr fremovexattr EXTRA fremovexattr i:is fremovexattr +alloc_hugepages EXTRA alloc_hugepages b:ianii __alloc_hugepages alloc_hugepages +free_hugepages EXTRA free_hugepages i:a __free_hugepages free_hugepages Index: sysdeps/unix/sysv/linux/sys/hugepage.h =================================================================== RCS file: sysdeps/unix/sysv/linux/sys/hugepage.h diff -N sysdeps/unix/sysv/linux/sys/hugepage.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ sysdeps/unix/sysv/linux/sys/sysdeps/unix/sysv/linux/sys/hugepage.h 3 Oct 2002 19:34:12 -0000 @@ -0,0 +1,75 @@ +/* Copyright (C) 2002 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _SYS_HUGEPAGE_H +#define _SYS_HUGEPAGE_H 1 + +/* This header file defines the huge page interface. A huge page is a + non-swappable (pinned) page of virtual memory. As the name + suggests, the size of a huge page is typically orders of magnitudes + bigger than the value returned by getpagesize(). For example, + depending on kernel configuration, on x86 it may be 2MBytes or + 4MBytes and on ia64 it is typically one of 16MB, 256MBytes, or + 4GBytes. Note that because huge pages are never swapped, they are + a relatively rare commodity and applications are expected to fall + back to allocating regular pages if a huge page cannot be + allocated. */ + +#include + +__BEGIN_DECLS + +/* Return the size of a huge page. */ + +extern long int __gethugepagesize (void) __attribute__ ((__const__)); +libc_hidden_proto (__gethugepagesize); + +/* Allocate LEN bytes worth of huge pages. LEN must be an integer + multiple of the huge page size. ADDR is the preferred starting + address for the memory. PROT is a mask of protection bits that + specify how the memory is to be mapped (PROT_NONE or any + combination of PROT_READ, PROT_WRITE, or PROT_EXEC). If KEY has is + a positive number, FLAG can be set to IPC_CREAT to request the + creation of a new shared memory segment or to zero to request + attaching to an existing shared memory segment. + + Return value: On success, alloc_hugepages() returns a pointer to + the allocated memory. On error, MAP_FAILED ((void *) -1) is + returned and ERRNO is set appropriately. + + Errors: + EINVAL LEN is not a integer multiple of gethugepagesize() + or KEY is a negative value. + + ENOENT No shared segment matching KEY was found and FLAGS + was zero. */ + +extern void *alloc_hugepages (int __key, void *__addr, size_t __len, + int __prot, int __flag); + +/* Free the huge page resources from the current process's address + space. ADDR must be an address returned by a previous call to + alloc_hugepages (). Note that for shared memory segments, the + underlying physical memory will be freed only after the last + process using them has freed them up or has exited. */ + +extern int free_hugepages (void *__addr); + +__END_DECLS + +#endif /* sys/hugepage.h */