Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp5045250pxu; Tue, 22 Dec 2020 07:09:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJwntCY5jexT1U9x1D4+I5xF56ld7lmJnJ/9ksQfGBRIyISF3xWgs1sKmZvPZ9KkFtJnxOCa X-Received: by 2002:a05:6402:3192:: with SMTP id di18mr20466995edb.332.1608649792789; Tue, 22 Dec 2020 07:09:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608649792; cv=none; d=google.com; s=arc-20160816; b=k3RPGzmwnHhI7UUR+EtZPcAyrHajeAdVVs491W9gk/pEN0S6CMBcklBga6vVmBlExU 8Fn7bf7fEN+ZYUXQiqaeY1jrj87d95QQX/ao3Iqy++hqWzLxumO4hwykR+OYQc0z0RkJ LhHFTFqj4Gm6MW9MkKfrglXZTF9i3qzx4NQxg5ax5K1hFBZg7O62vpghU6vfVLdMra9E rTywH7cnTH0lndcLP3fsuEbLtHctw8KOkXc4+VBr7NlsIvvjyH+k4U6qZXEleF8Fj8JL 1Vp6qBxnjmyvMqM0cT/ecUubeN9oRZBjprhsNtqATBZXs2knGp9+Snz+eiwUSC7LNTal 9vPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Vg4rXkTJ1RSjS9v+aXpVjxDf/4HIRC34j1tsJCwhiy0=; b=VMMcLlgJMGmmiEQ/AsiXpGaTdDnC8glcvJnvU99q6cS8IUe/Np7QzPgkkeEWr63HMm n8847iqjBmVYDzKuW/7Vr++4AOaTjxAuk/cMJxLIYDIFkwT4v76WIfexZQB3nghyM6KS PCGMktcWm6x6vMKt/LoBZ/4q1mPY462JVpqWbUgESvDcBzpG4LzA7G1IEbDTzp6SXn2N qKvm2O0aWoEGOXaYrTZkHYfkZEnPvg6f93RtBd4glbj80cDmN0js0PPiBtznuF9+N5hM vh6XNFn4Z2WgX1xU/uw2gohMjJ8JB81f1oC9uHk2yw7ZN5MYmU8D9m4vm7IO57yHV3N+ Buew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="EEq/OnT3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g16si12217535ejf.689.2020.12.22.07.09.30; Tue, 22 Dec 2020 07:09:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="EEq/OnT3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727224AbgLVPIt (ORCPT + 99 others); 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-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 > >