LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-23-2004, 10:29 PM   #1
eshwar_ind
Member
 
Registered: Feb 2004
Location: Bangalore
Distribution: Redhat
Posts: 144

Rep: Reputation: 15
get Page size


Hi!
How can we get the page size in linux. Can i change that in in aprogram?
In Kernel module programming is there any way to get the memory pieces just like 10 bytes, 2 bytes? ( i think kmalloc allocates entire page if the requested memory is less than the page size So its a waste of remaining memory)
Please reply me.
bye,
Eshwar.
 
Old 02-24-2004, 03:01 AM   #2
jinksys
Member
 
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 419

Rep: Reputation: 35
To get page size:

Code:
#include <stdio.h>
#include <unistd.h>

int main()
{
printf("%i,	getpagesize());
return 0;
}
Simply put, you cant change the page size. And due to the way the kernel allocates memory and fragmentation within the system's physical memory, memory allocation with kmalloc isn't precise as with malloc. You'll often get a pointer to a larger chunk of memory than requested, sometimes up to double the amount.

Last edited by jinksys; 02-24-2004 at 03:04 AM.
 
Old 02-24-2004, 01:45 PM   #3
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
to add one thing to the above, kmalloc keeps around a pool of various sized memory objects. whether or not there is one as small as 10 bytes, i doubt, but you should recieve the next largest chunk if that pool has a free chunk. if you are going to be allocating a large quantity of constant size memory chunks, you may want to look into having kmalloc create a special pool of objects for you of that size using kmem_cache_create() and kmem_cache_alloc() from [kernel/slab/mm.c].
 
Old 02-24-2004, 07:17 PM   #4
jinksys
Member
 
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 419

Rep: Reputation: 35
I seriously doubt youll get a buffer of 10bytes using kmalloc, since the minimum memory that kmalloc handles is anywhere from 32 to 64 bytes, depending on page size and kernel.
 
Old 02-24-2004, 11:49 PM   #5
eshwar_ind
Member
 
Registered: Feb 2004
Location: Bangalore
Distribution: Redhat
Posts: 144

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by jinksys
I seriously doubt youll get a buffer of 10bytes using kmalloc, since the minimum memory that kmalloc handles is anywhere from 32 to 64 bytes, depending on page size and kernel.
 
Old 02-24-2004, 11:50 PM   #6
eshwar_ind
Member
 
Registered: Feb 2004
Location: Bangalore
Distribution: Redhat
Posts: 144

Original Poster
Rep: Reputation: 15
Hi guys thank you very much.
 
Old 09-27-2014, 11:20 PM   #7
dhirendracool1
LQ Newbie
 
Registered: Sep 2014
Posts: 1

Rep: Reputation: Disabled
HI,

When I am trying to getpagefile(), it is always returning me 4096. Can you please help.

I am reallocating the memory from 4096 to 2048 through realloc(), but everytime it is giving me 4096.

Thanks,
 
Old 09-28-2014, 05:39 AM   #8
mina86
Member
 
Registered: Aug 2008
Distribution: Slackware
Posts: 463

Rep: Reputation: 192Reputation: 192
Quote:
Originally Posted by jinksys View Post
I seriously doubt youll get a buffer of 10bytes using kmalloc, since the minimum memory that kmalloc handles is anywhere from 32 to 64 bytes, depending on page size and kernel.
Nope, the smallest is 8 bytes. Next is 16, so one ends up wasting “just” 6 bytes when allocating 10. See kmalloc_index function and /proc/slabinfo file on your system.

PS. There is a ksize function which can be used to figure out actual size of allocated memory.

Last edited by mina86; 09-28-2014 at 05:59 AM.
 
Old 09-29-2014, 09:13 AM   #9
jinksys
Member
 
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 419

Rep: Reputation: 35
Quote:
Originally Posted by dhirendracool1 View Post
HI,

When I am trying to getpagefile(), it is always returning me 4096. Can you please help.

I am reallocating the memory from 4096 to 2048 through realloc(), but everytime it is giving me 4096.

Thanks,
Did you mean getpagesize() ?
Also, keep in mind everything I said in my posts is over ten years old, so things may have changed.
 
Old 09-29-2014, 11:46 AM   #10
mina86
Member
 
Registered: Aug 2008
Distribution: Slackware
Posts: 463

Rep: Reputation: 192Reputation: 192
Quote:
Originally Posted by dhirendracool1 View Post
When I am trying to getpagefile(), it is always returning me 4096. Can you please help.

I am reallocating the memory from 4096 to 2048 through realloc(), but everytime it is giving me 4096.
On a given system getpagesize will always return the same value – the page size for that architecture. What do you think page size is? What are you trying to accomplish?
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
OpenOffice.org 2.0RC - Default Page Size A4 ? Yalla-One Linux - Software 6 10-28-2005 11:00 AM
adjusting the size of a web page mrobertson Programming 1 08-10-2005 08:50 AM
Next page link size azucaro LQ Suggestions & Feedback 1 06-13-2005 06:51 PM
Page size in printing jontyrhodes Linux - General 2 05-21-2004 08:20 PM
Cups/Printer Page size matt3333 Linux - Software 26 03-16-2004 10:41 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration