LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 09-15-2016, 10:36 PM   #31
Sefyir
Member
 
Registered: Mar 2015
Distribution: Linux Mint
Posts: 394

Rep: Reputation: 161Reputation: 161

Quote:
Originally Posted by Thirdeyematt View Post
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?
 
Old 09-18-2016, 03:00 PM   #32
Thirdeyematt
Member
 
Registered: Aug 2016
Posts: 31

Original Poster
Rep: Reputation: Disabled
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?
 
Old 09-18-2016, 05:11 PM   #33
Thirdeyematt
Member
 
Registered: Aug 2016
Posts: 31

Original Poster
Rep: Reputation: Disabled
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.
 
Old 09-18-2016, 09:15 PM   #34
JeremyBoden
Member
 
Registered: Nov 2011
Posts: 939

Rep: Reputation: 174Reputation: 174
Nothing happens instantly.
It's a finite world.

Never heard of baca decimal.

I suggest you write a more practical program.
 
Old 09-19-2016, 03:15 AM   #35
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,133

Rep: Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273
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?
 
Old 09-25-2016, 08:15 PM   #36
Thirdeyematt
Member
 
Registered: Aug 2016
Posts: 31

Original Poster
Rep: Reputation: Disabled
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.
 
Old 09-25-2016, 08:18 PM   #37
Thirdeyematt
Member
 
Registered: Aug 2016
Posts: 31

Original Poster
Rep: Reputation: Disabled
Oh wait just found it: for () do cp file file-$i ; done
 
Old 09-26-2016, 08:17 AM   #38
JeremyBoden
Member
 
Registered: Nov 2011
Posts: 939

Rep: Reputation: 174Reputation: 174
Congratulations.

Quite pointless, of course.
 
Old 09-26-2016, 08:46 AM   #39
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,133

Rep: Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273
see post #27
 
Old 09-26-2016, 09:55 AM   #40
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
Quote:
Originally Posted by JeremyBoden View Post
Congratulations.

Quite pointless, of course.
You didn't mention the problems a 100000 files in a single directory could cause...
 
Old 10-06-2016, 09:42 PM   #41
Thirdeyematt
Member
 
Registered: Aug 2016
Posts: 31

Original Poster
Rep: Reputation: Disabled
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;
}
 
Old 10-06-2016, 10:28 PM   #42
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
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.
 
Old 10-07-2016, 05:27 PM   #43
Thirdeyematt
Member
 
Registered: Aug 2016
Posts: 31

Original Poster
Rep: Reputation: Disabled
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
 
Old 10-07-2016, 09:28 PM   #44
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
Quote:
Originally Posted by Thirdeyematt View Post
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.
 
Old 10-08-2016, 07:58 AM   #45
Thirdeyematt
Member
 
Registered: Aug 2016
Posts: 31

Original Poster
Rep: Reputation: Disabled
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.
 
  


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
[SOLVED] swap file, virtual memory Art McClure Slackware 2 04-08-2012 11:56 AM
Where to put Bash scripts written to run at various times to examine Alsa sound probs xologist Linux - Software 3 08-13-2008 11:09 AM
Difference between resident memory,shared memory and virtual memory in system monitor mathimca05 Linux - Newbie 1 11-11-2007 05:05 AM
Information for virtual memory file system peiwai Linux - Software 1 05-01-2006 01:09 PM
RH 8.0 Mapping Virtual Memory to get access to VMIC Reflective Memory PCI card. Merlin53 Linux - Hardware 0 05-05-2003 01:50 PM


All times are GMT -5. The time now is 07:01 PM.

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