Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
|
09-15-2016, 10:36 PM
|
#31
|
Member
Registered: Mar 2015
Distribution: Linux Mint
Posts: 634
|
Quote:
Originally Posted by Thirdeyematt
Well I took a look at the manual, I didn't see a cp command, does this have the function of the map file command without actually having to declare an array that the file is being mapped to?
|
You typed man cp in the terminal?
|
|
|
09-18-2016, 03:00 PM
|
#32
|
Member
Registered: Aug 2016
Posts: 31
Original Poster
Rep:
|
Ok, so I will create 100k memory maps of my file length, and then write each file into the memory map. It says to type in the length of the new mapping, so for a file that is 99.4 mb, do I just type in 99,400,00 for the length of the file?
|
|
|
09-18-2016, 05:11 PM
|
#33
|
Member
Registered: Aug 2016
Posts: 31
Original Poster
Rep:
|
Well I have the code here in Java:
http://howtodoinjava.com/java-7/nio/...ffer-tutorial/
It makes the memory mapping in baca decimal, so for 99.4 mb it would be 0x5ECB940, then I write a code to do this and I don't think that it will be able to create 100k memory mapped files and copy 100k files into them instantly. That is the same problem I had in Java.
|
|
|
09-18-2016, 09:15 PM
|
#34
|
Senior Member
Registered: Nov 2011
Location: London, UK
Distribution: Debian
Posts: 1,950
|
Nothing happens instantly.
It's a finite world.
Never heard of baca decimal.
I suggest you write a more practical program.
|
|
|
09-19-2016, 03:15 AM
|
#35
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 23,468
|
what the heck is baca decimal?
You may use the command ls to check the size of a file, in bytes. Or try wc (see man pages for detailed usage).
What is the problem with cp?
Quote:
I don't think that it will be able to create 100k memory mapped files and copy 100k files into them instantly.
|
Why??? Where is this coming from?
|
|
|
09-25-2016, 08:15 PM
|
#36
|
Member
Registered: Aug 2016
Posts: 31
Original Poster
Rep:
|
I meant to say hexa decimal but I am going to try a new way. Since all of Linux is already run using virtual memory, my plan is to just copy the same file over and over again 100k times into the same folder. So I put the file into the main directory that the terminal uses. When I type in the code:
For I in {1..100000} ; do cp FILE ~/ ; done
I get the msg that they are both the same file... Is there a way to use the cp command to rename them all different names in the same code somehow? I've tried looking online but it says to use -a and then when I do it still doesn't work. -a is the archive command.
|
|
|
09-25-2016, 08:18 PM
|
#37
|
Member
Registered: Aug 2016
Posts: 31
Original Poster
Rep:
|
Oh wait just found it: for () do cp file file-$i ; done
|
|
|
09-26-2016, 08:17 AM
|
#38
|
Senior Member
Registered: Nov 2011
Location: London, UK
Distribution: Debian
Posts: 1,950
|
Congratulations.
Quite pointless, of course.
|
|
|
09-26-2016, 08:46 AM
|
#39
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 23,468
|
see post #27
|
|
|
09-26-2016, 09:55 AM
|
#40
|
Senior Member
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,908
|
Quote:
Originally Posted by JeremyBoden
Congratulations.
Quite pointless, of course.
|
You didn't mention the problems a 100000 files in a single directory could cause...
|
|
|
10-06-2016, 09:42 PM
|
#41
|
Member
Registered: Aug 2016
Posts: 31
Original Poster
Rep:
|
I just wanted to update this again: I still have not found any working solution to filling up the virtual memory with one file, I have been trying things posted and checking the virtual memory in use using: free -t Nothing shows up. So I will post my code here, I believe that it isn't working because it is just using the same virtual memory address each time it does a new memory mapping? I looped it 200k times using the for loop but after I check the virtual memory usage using free -t I dont see any swap space being used.
/* For the size of the file. */
#include <sys/stat.h>
/* This contains the mmap calls. */
#include <sys/mman.h>
/* These are for error printing. */
#include <errno.h>
#include <string.h>
#include <stdarg.h>
/* This is for open. */
#include <fcntl.h>
#include <stdio.h>
/* For exit. */
#include <stdlib.h>
/* For the final part of the example. */
#include <ctype.h>
/* "check" checks "test" and prints an error and exits if it is
true. */
static void
check (int test, const char * message, ...)
{
if (test) {
va_list args;
va_start (args, message);
vfprintf (stderr, message, args);
va_end (args);
fprintf (stderr, "\n");
exit (EXIT_FAILURE);
}
}
int main ()
{
/* The file descriptor. */
int fd;
/* Information about the file. */
struct stat s;
int status;
size_t size;
/* The file name to open. */
const char * file_name = "MentalClarity.png";
/* The memory-mapped thing itself. */
const char * mapped[200000];
int i;
/* Open the file for reading. */
fd=open("MentalClarity.png", O_RDWR);
check (fd < 0, "open %s failed: %s", file_name, strerror (errno));
/* Get the size of the file. */
status = fstat (fd, & s);
check (status < 0, "stat %s failed: %s", file_name, strerror (errno));
size = s.st_size;
for (int scount=1;scount<=200000;scount++) {
/* Memory-map the file. */
mapped[scount] = mmap (0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
check (mapped[scount] == MAP_FAILED, "mmap %s failed: %s",
file_name, strerror (errno));
}
return 0;
}
|
|
|
10-06-2016, 10:28 PM
|
#42
|
Senior Member
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,908
|
Why should it do anything but what you told it to do? You opened the file, you mapped it.
Nothing else. Each time you call mmap all you do is set the amount - and just set it to the same thing. It was put in your virtual memory map, all 200,000 times...
All you did was use up system time on one system call.
One last thing - once you exited the virtual memory got released.
Perhaps you need to understand what virtual memory really is:
https://en.wikipedia.org/wiki/Virtual_memory
None of what you did requires physical memory (well, maybe 1.5MB for the array and some for the executable). It is all virtual...
Last edited by jpollard; 10-07-2016 at 11:21 AM.
|
|
|
10-07-2016, 05:27 PM
|
#43
|
Member
Registered: Aug 2016
Posts: 31
Original Poster
Rep:
|
Oh I see, so I ran the program and then exited the program, and then the virtual memory disappeared because the program was the only thing that was using it... I'll change the script to allow the program to run continuously after the memory mappings and then test the virtual memory with free -t
|
|
|
10-07-2016, 09:28 PM
|
#44
|
Senior Member
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,908
|
Quote:
Originally Posted by Thirdeyematt
Oh I see, so I ran the program and then exited the program, and then the virtual memory disappeared because the program was the only thing that was using it... I'll change the script to allow the program to run continuously after the memory mappings and then test the virtual memory with free -t
|
It won't change unless something directs the system to access the pages. After that, pages will be dropped to be reused for other pages...
As long as nothing access the pages you won't see any changes.
|
|
|
10-08-2016, 07:58 AM
|
#45
|
Member
Registered: Aug 2016
Posts: 31
Original Poster
Rep:
|
Oh ok so I need to make the program read each memory mapping continuously and then have the file run until I want it to exit? That way the memory mappings will all stay running right?
Last edited by Thirdeyematt; 10-08-2016 at 08:54 AM.
|
|
|
All times are GMT -5. The time now is 04:18 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|