From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A11A1C433DB for ; Tue, 22 Dec 2020 15:09:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 77BCF22583 for ; Tue, 22 Dec 2020 15:09:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727903AbgLVPIt (ORCPT ); Tue, 22 Dec 2020 10:08:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726920AbgLVPIs (ORCPT ); Tue, 22 Dec 2020 10:08:48 -0500 Received: from mail-ua1-x933.google.com (mail-ua1-x933.google.com [IPv6:2607:f8b0:4864:20::933]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2FA8C0613D3 for ; Tue, 22 Dec 2020 07:08:08 -0800 (PST) Received: by mail-ua1-x933.google.com with SMTP id f16so4437802uav.12 for ; Tue, 22 Dec 2020 07:08:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Vg4rXkTJ1RSjS9v+aXpVjxDf/4HIRC34j1tsJCwhiy0=; b=EEq/OnT3s6THYE1mfOGdHX0XzUpZjLU87XJ256AUL7ssWp2wb2sMsIaLH7B8+h8Wwd enqIS47nOCOHDhZX40eV9wnaBYjsWPLshftZBceKLyVTfTG4eVoILyo0N2Fh4+Ey6vO/ ODn+vaVqXEBho4XxnQXXbXA+KiLBSu+lht3FqsFwpQJ/gd6txg+WdVPNtfcCQaCrhkyU Yz9vBgppwOVSoSGrIBuITgFlV/RT49VH8HkFZdqmY5MTVyR4aCC3KcImNdQcEOUzojYR ygE9A1+NGYEDLUPBX915EnpUuk9gER/h2ZLvWVvylmK1SeNeIEOxPSPhXH2SoAKk8zXa bsag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Vg4rXkTJ1RSjS9v+aXpVjxDf/4HIRC34j1tsJCwhiy0=; b=hDlSswO/tr0aUaMqu9rsCXTK2+qGaUqqsItYLTEzhyk441AeBzwlKHNNP5CVFbFXGG ec/wcyNkdkCtSGSlniWe9WvNyQo78YEl6YG4Px2dvLmiGd96RzXDWrdLkHP10UUxVLUN 7PoIG8QmckmQqbeGXPRBIc1VkTL8KeValAOHgb00vJO7WxwCXLNIYLP3u/tYs9fpjytG ULws8vjevKIOVG8zRsgSk75Q3+UWDtaZ2aWjzzqeWWXs9C/bgQc3+rcgTJ0dRivRHlxc sHrRMZoxnzq6lELt7WX8bkOEOCUnqMM6VB3XnX9XuQEX/cs9LRwyv29foZ22o8iR+5CC n/1g== X-Gm-Message-State: AOAM5325V8Fbaf2y7lszayMg6fHwUPGwfAy1qbDoyoVuHOk91IWyvXQh u8iUcGuWcdhfG6M688mL7YH8VE0GEvWWiOjfpXU= X-Google-Smtp-Source: ABdhPJz7xctMff6Y7t2PkT1UIdR/DFlB2RTAjl6gmUJvTWVB3c2qtLBZ7l29fXx5kKdM7Vs7cVMi+hNqyO3ISBvXGsY= X-Received: by 2002:ab0:1c0a:: with SMTP id a10mr15591875uaj.89.1608649687685; Tue, 22 Dec 2020 07:08:07 -0800 (PST) MIME-Version: 1.0 References: <20201222121904.50845-1-qianjun.kernel@gmail.com> In-Reply-To: <20201222121904.50845-1-qianjun.kernel@gmail.com> From: Souptick Joarder Date: Tue, 22 Dec 2020 20:37:55 +0530 Message-ID: Subject: Re: [PATCH 1/1] mm:improve the performance during fork To: qianjun.kernel@gmail.com Cc: Andrew Morton , Linux-MM , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 22, 2020 at 5:49 PM wrote: > > From: jun qian > > In our project, Many business delays come from fork, so > we started looking for the reason why fork is time-consuming. > I used the ftrace with function_graph to trace the fork, found > that the vm_normal_page will be called tens of thousands and > the execution time of this vm_normal_page function is only a > few nanoseconds. And the vm_normal_page is not a inline function. > So I think if the function is inline style, it maybe reduce the > call time overhead. > > I did the following experiment: > > I have wrote the c test code, pls ignore the memory leak :) > Before fork, I will malloc 4G bytes, then acculate the fork > time. > > int main() > { > char *p; > unsigned long long i=0; > float time_use=0; > struct timeval start; > struct timeval end; > > for(i=0; i p = (char *)malloc(4096); > if (p == NULL) { > printf("malloc failed!\n"); > return 0; > } > p[0] = 0x55; > } > gettimeofday(&start,NULL); > fork(); > gettimeofday(&end,NULL); > > time_use=(end.tv_sec * 1000000 + end.tv_usec) - > (start.tv_sec * 1000000 + start.tv_usec); > printf("time_use is %.10f us\n",time_use); > > return 0; > } > > We need to compare the changes in the size of vmlinux, the time of > fork in inline and non-inline cases, and the vm_normal_page will be > called in many function. So we also need to compare this function's > size. For examples, the do_wp_page will call vm_normal_page, so I > also calculated it's size. > > inline non-inline diff > vmlinux size 9709248 bytes 9709824 bytes -576 bytes > fork time 23475ns 24638ns -4.7% Do you have time diff for both parent and child process ? > do_wp_page size 972 743 +229 > > According to the above test data, I think inline vm_normal_page can > reduce fork execution time. > > Signed-off-by: jun qian > --- > mm/memory.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/mm/memory.c b/mm/memory.c > index 7d608765932b..a689bb5d3842 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -591,7 +591,7 @@ static void print_bad_pte(struct vm_area_struct *vma, unsigned long addr, > * PFNMAP mappings in order to support COWable mappings. > * > */ > -struct page *vm_normal_page(struct vm_area_struct *vma, unsigned long addr, > +inline struct page *vm_normal_page(struct vm_area_struct *vma, unsigned long addr, > pte_t pte) > { > unsigned long pfn = pte_pfn(pte); > -- > 2.18.2 > > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB470C433E0 for ; Tue, 22 Dec 2020 15:08:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 62A7722583 for ; Tue, 22 Dec 2020 15:08:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 62A7722583 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id CE9928D0013; Tue, 22 Dec 2020 10:08:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C9ADE8D0012; Tue, 22 Dec 2020 10:08:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BAFE48D0013; Tue, 22 Dec 2020 10:08:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0221.hostedemail.com [216.40.44.221]) by kanga.kvack.org (Postfix) with ESMTP id A63928D0012 for ; Tue, 22 Dec 2020 10:08:09 -0500 (EST) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 61445180ACF62 for ; Tue, 22 Dec 2020 15:08:09 +0000 (UTC) X-FDA: 77621248698.03.kite48_4616b8227460 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin03.hostedemail.com (Postfix) with ESMTP id 400EC15008 for ; Tue, 22 Dec 2020 15:08:09 +0000 (UTC) X-HE-Tag: kite48_4616b8227460 X-Filterd-Recvd-Size: 5561 Received: from mail-ua1-f41.google.com (mail-ua1-f41.google.com [209.85.222.41]) by imf26.hostedemail.com (Postfix) with ESMTP for ; Tue, 22 Dec 2020 15:08:08 +0000 (UTC) Received: by mail-ua1-f41.google.com with SMTP id 17so4448689uaq.4 for ; Tue, 22 Dec 2020 07:08:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Vg4rXkTJ1RSjS9v+aXpVjxDf/4HIRC34j1tsJCwhiy0=; b=EEq/OnT3s6THYE1mfOGdHX0XzUpZjLU87XJ256AUL7ssWp2wb2sMsIaLH7B8+h8Wwd enqIS47nOCOHDhZX40eV9wnaBYjsWPLshftZBceKLyVTfTG4eVoILyo0N2Fh4+Ey6vO/ ODn+vaVqXEBho4XxnQXXbXA+KiLBSu+lht3FqsFwpQJ/gd6txg+WdVPNtfcCQaCrhkyU Yz9vBgppwOVSoSGrIBuITgFlV/RT49VH8HkFZdqmY5MTVyR4aCC3KcImNdQcEOUzojYR ygE9A1+NGYEDLUPBX915EnpUuk9gER/h2ZLvWVvylmK1SeNeIEOxPSPhXH2SoAKk8zXa bsag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Vg4rXkTJ1RSjS9v+aXpVjxDf/4HIRC34j1tsJCwhiy0=; b=JoPBc9DZcrwy0xPI4mNBzR+601MCsk1WeMBPZwPvQ2AdufVLCCG8gZAAVPeObgchZ4 evH9/9iojW2TqvnI3j05rqyS56AFcOUl3VofBddfuOTe2NwgJ5ub6K4kR8RtCoJ1jFBq ifsJA6vqloMiw81+EnXZr+H8lj9bgm032Mw9CW91jOqS7uERtakqq4X8WO2E0TUmzZ1U wUZhdvNbhnFLoOB+yJdpSAaLQHyH+pzR07IsnlnLU/B83NEPVbx/NQOxLGyY0CrgEiab qalixqX4HKc2KHDUX2CiOfwin33K+HclBi5X/in4biuPbi1vgVLRDkReqrTmpmVKJCvX +Qmg== X-Gm-Message-State: AOAM531BucQveX6Ta/8+1kb7eqosiQYcYjFvG2dQ5029abPh5mYhuc9n f4yGXUi6VoIgX3jXoLt7topOu9f09wlDVmdNTRQ= X-Google-Smtp-Source: ABdhPJz7xctMff6Y7t2PkT1UIdR/DFlB2RTAjl6gmUJvTWVB3c2qtLBZ7l29fXx5kKdM7Vs7cVMi+hNqyO3ISBvXGsY= X-Received: by 2002:ab0:1c0a:: with SMTP id a10mr15591875uaj.89.1608649687685; Tue, 22 Dec 2020 07:08:07 -0800 (PST) MIME-Version: 1.0 References: <20201222121904.50845-1-qianjun.kernel@gmail.com> In-Reply-To: <20201222121904.50845-1-qianjun.kernel@gmail.com> From: Souptick Joarder Date: Tue, 22 Dec 2020 20:37:55 +0530 Message-ID: Subject: Re: [PATCH 1/1] mm:improve the performance during fork To: qianjun.kernel@gmail.com Cc: Andrew Morton , Linux-MM , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Dec 22, 2020 at 5:49 PM wrote: > > From: jun qian > > In our project, Many business delays come from fork, so > we started looking for the reason why fork is time-consuming. > I used the ftrace with function_graph to trace the fork, found > that the vm_normal_page will be called tens of thousands and > the execution time of this vm_normal_page function is only a > few nanoseconds. And the vm_normal_page is not a inline function. > So I think if the function is inline style, it maybe reduce the > call time overhead. > > I did the following experiment: > > I have wrote the c test code, pls ignore the memory leak :) > Before fork, I will malloc 4G bytes, then acculate the fork > time. > > int main() > { > char *p; > unsigned long long i=0; > float time_use=0; > struct timeval start; > struct timeval end; > > for(i=0; i p = (char *)malloc(4096); > if (p == NULL) { > printf("malloc failed!\n"); > return 0; > } > p[0] = 0x55; > } > gettimeofday(&start,NULL); > fork(); > gettimeofday(&end,NULL); > > time_use=(end.tv_sec * 1000000 + end.tv_usec) - > (start.tv_sec * 1000000 + start.tv_usec); > printf("time_use is %.10f us\n",time_use); > > return 0; > } > > We need to compare the changes in the size of vmlinux, the time of > fork in inline and non-inline cases, and the vm_normal_page will be > called in many function. So we also need to compare this function's > size. For examples, the do_wp_page will call vm_normal_page, so I > also calculated it's size. > > inline non-inline diff > vmlinux size 9709248 bytes 9709824 bytes -576 bytes > fork time 23475ns 24638ns -4.7% Do you have time diff for both parent and child process ? > do_wp_page size 972 743 +229 > > According to the above test data, I think inline vm_normal_page can > reduce fork execution time. > > Signed-off-by: jun qian > --- > mm/memory.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/mm/memory.c b/mm/memory.c > index 7d608765932b..a689bb5d3842 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -591,7 +591,7 @@ static void print_bad_pte(struct vm_area_struct *vma, unsigned long addr, > * PFNMAP mappings in order to support COWable mappings. > * > */ > -struct page *vm_normal_page(struct vm_area_struct *vma, unsigned long addr, > +inline struct page *vm_normal_page(struct vm_area_struct *vma, unsigned long addr, > pte_t pte) > { > unsigned long pfn = pte_pfn(pte); > -- > 2.18.2 > >