From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx162.postini.com [74.125.245.162]) by kanga.kvack.org (Postfix) with SMTP id CFB306B0032 for ; Thu, 9 May 2013 10:33:24 -0400 (EDT) Received: by mail-oa0-f49.google.com with SMTP id k14so1967814oag.36 for ; Thu, 09 May 2013 07:33:24 -0700 (PDT) Received: from [192.168.0.100] (69-196-135-35.dsl.teksavvy.com. [69.196.135.35]) by mx.google.com with ESMTPSA id n6sm3404831oel.8.2013.05.09.07.33.22 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 09 May 2013 07:33:23 -0700 (PDT) Message-ID: <518BB3B1.8010207@gmail.com> Date: Thu, 09 May 2013 10:33:21 -0400 From: Ben Teissier MIME-Version: 1.0 Subject: misunderstanding of the virtual memory References: <518BB132.5050802@gmail.com> In-Reply-To: <518BB132.5050802@gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: linux-mm@kvack.org Hi, I'm Benjamin and I'm studying the kernel. I write you this email because I've a trouble with the mmu and the virtual memory. I try to understand how a program (user land) can write something into the stack (push ebp, for example), indeed, the program works with virtual address (between 0x00000 and 0x8... if my memory is good) but at the hardware side the address is not the same (that's why mmu was created, if I'm right). My problem is the following : how the data is wrote on the physical memory. When I try a strace (kernel 2.6.32 on a simple program) I have no hint on the transfer of data. Moreover, according to the wikipedia web page on syscall ( https://en.wikipedia.org/wiki/System_call#The_library_as_an_intermediary ), a call is not managed by the kernel. So, how the transfer between virtual memory and physical memory is possible ? I hope my email is understandable, I tried to put words on my troubles. Thanks a lot for your help and have a nice day. Benjamin. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx180.postini.com [74.125.245.180]) by kanga.kvack.org (Postfix) with SMTP id 2D7F36B0039 for ; Thu, 9 May 2013 12:57:31 -0400 (EDT) Received: from /spool/local by e8.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 9 May 2013 12:57:30 -0400 Received: from d01relay01.pok.ibm.com (d01relay01.pok.ibm.com [9.56.227.233]) by d01dlp03.pok.ibm.com (Postfix) with ESMTP id 13638C9001A for ; Thu, 9 May 2013 12:57:28 -0400 (EDT) Received: from d01av01.pok.ibm.com (d01av01.pok.ibm.com [9.56.224.215]) by d01relay01.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r49GvSxJ306020 for ; Thu, 9 May 2013 12:57:28 -0400 Received: from d01av01.pok.ibm.com (loopback [127.0.0.1]) by d01av01.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r49GvIYs026187 for ; Thu, 9 May 2013 12:57:19 -0400 Date: Thu, 9 May 2013 11:57:17 -0500 From: Seth Jennings Subject: Re: misunderstanding of the virtual memory Message-ID: <20130509165717.GA9548@medulla> References: <518BB132.5050802@gmail.com> <518BB3B1.8010207@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <518BB3B1.8010207@gmail.com> Sender: owner-linux-mm@kvack.org List-ID: To: Ben Teissier Cc: linux-mm@kvack.org On Thu, May 09, 2013 at 10:33:21AM -0400, Ben Teissier wrote: > > Hi, > > I'm Benjamin and I'm studying the kernel. I write you this email > because I've a trouble with the mmu and the virtual memory. I try to > understand how a program (user land) can write something into the stack > (push ebp, for example), indeed, the program works with virtual address > (between 0x00000 and 0x8... if my memory is good) but at the hardware > side the address is not the same (that's why mmu was created, if I'm right). Yes, this is the purpose of pages tables; to map virtual addresses to real memory addresses (more precisely virtual memory _pages_ to real memory pages). > > My problem is the following : how the data is wrote on the physical > memory. When I try a strace (kernel 2.6.32 on a simple program) I have > no hint on the transfer of data. Moreover, according to the wikipedia > web page on syscall ( > https://en.wikipedia.org/wiki/System_call#The_library_as_an_intermediary > ), a call is not managed by the kernel. So, how the transfer between > virtual memory and physical memory is possible ? That is because writing to a memory location in userspace isn't an operation that requires a syscall or any kind of kernel intervention at all. It is an assembly store instruction executed directly on the CPU by the program. The only time the kernel is involved in a store operation is if the virtual address translation doesn't exist in the TLB (or is write-protected, etc..), in which case the hardware generates a fault so the kernel take the required action to populate the TLB with the translation. Hope this answers your question. Seth -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx191.postini.com [74.125.245.191]) by kanga.kvack.org (Postfix) with SMTP id 852F46B0033 for ; Fri, 10 May 2013 11:57:46 -0400 (EDT) Received: by mail-ie0-f173.google.com with SMTP id k5so8330102iea.4 for ; Fri, 10 May 2013 08:57:45 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <20130509165717.GA9548@medulla> References: <518BB132.5050802@gmail.com> <518BB3B1.8010207@gmail.com> <20130509165717.GA9548@medulla> Date: Fri, 10 May 2013 11:57:45 -0400 Message-ID: Subject: Re: misunderstanding of the virtual memory From: Benjamin Teissier Content-Type: text/plain; charset=ISO-8859-1 Sender: owner-linux-mm@kvack.org List-ID: To: Seth Jennings Cc: linux-mm@kvack.org 2013/5/9, Seth Jennings : > On Thu, May 09, 2013 at 10:33:21AM -0400, Ben Teissier wrote: >> >> Hi, >> >> I'm Benjamin and I'm studying the kernel. I write you this email >> because I've a trouble with the mmu and the virtual memory. I try to >> understand how a program (user land) can write something into the stack >> (push ebp, for example), indeed, the program works with virtual address >> (between 0x00000 and 0x8... if my memory is good) but at the hardware >> side the address is not the same (that's why mmu was created, if I'm >> right). > > Yes, this is the purpose of pages tables; to map virtual addresses to real > memory addresses (more precisely virtual memory _pages_ to real memory > pages). > >> >> My problem is the following : how the data is wrote on the physical >> memory. When I try a strace (kernel 2.6.32 on a simple program) I have >> no hint on the transfer of data. Moreover, according to the wikipedia >> web page on syscall ( >> https://en.wikipedia.org/wiki/System_call#The_library_as_an_intermediary >> ), a call is not managed by the kernel. So, how the transfer between >> virtual memory and physical memory is possible ? > > That is because writing to a memory location in userspace isn't an > operation > that requires a syscall or any kind of kernel intervention at all. It is > an > assembly store instruction executed directly on the CPU by the program. > The > only time the kernel is involved in a store operation is if the virtual > address > translation doesn't exist in the TLB (or is write-protected, etc..), in > which > case the hardware generates a fault so the kernel take the required action > to > populate the TLB with the translation. > > Hope this answers your question. > > Seth > > Hi, Your answer is perfect, thanks a lot for your help ! Benjamin. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org