Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3627510ybi; Mon, 27 May 2019 03:18:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqyIxxdDMxJxsRBpxcQNL1e9QxuIg2DKzZ8ESoTrI/HNlogqOK9Qv14MN14CVv8EWOC5N4V8 X-Received: by 2002:a63:6e86:: with SMTP id j128mr22843796pgc.161.1558952333956; Mon, 27 May 2019 03:18:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558952333; cv=none; d=google.com; s=arc-20160816; b=UUHLW+gO4lmLurdMPLP/G5i62VhB57QaCOOznIcFeePfc9uw67UTN7o4gM/tD5cHBw rMK/CJcc1pjQMYCRgjWTvBBpBZfR6OK/23wJRdX+QQ0Mw2GIXuS4wpfLmt24OAuNAoyE /DkxuWtdBsCVVVoZRSnxe414RR5JlXXB7v6iHPVKhONM32m4YaFVhf4X7PDQ7nrXt9WO mYby6THQFEDwaOyZpAmQ5q1u+Cc3ueuLrgMacNGWYBJXnEb+UIt6i0nrHUOF0/JuIPIU 1gIhzjZ8b4cmOwUauqsYTt58Vijtp/l2LBED2f+Vzlagi8A1QuHgqofvVY8D1+Q8scQ1 YuMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:reply-to:subject:cc:to:from:date; bh=VoZU80vjMSHcUl+cQ95tumijcV0EGe9EpepwnMY8E1g=; b=qbEXrpss0YW1SsPdfs9Qp/Ztun+POitzEreupg36vtFzQNnRx2qmt3J0R8GP49N66L z0tiev5K/UAW8k7813v6mhNxEX16v6Qv6rvNG9szXa9iKOdp45J8tRWljcSV8RLFjqOf cZBZKFFbFb4qzI+tK7hfzM0Zxht7AaY4Fpr520g88eprQOCZA8I2+fFsqwuiW7G00dTH pSf+y/Ljx1e76Z6FameJfIb9/h4lAIecUtXxqXo/ifJkYGGIGJfVyW2Jrm5okxWhd8mO LKVZiOr60b6P6TvJedeXXEVhZFwNlXRtyIur+QwVRXGm1LdGxDx2F3xqWVgPbVKrFNzf bD1Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c3si18680491pfr.27.2019.05.27.03.18.38; Mon, 27 May 2019 03:18:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726234AbfE0KQ6 (ORCPT + 99 others); Mon, 27 May 2019 06:16:58 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:33584 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725943AbfE0KQ5 (ORCPT ); Mon, 27 May 2019 06:16:57 -0400 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x4RADOiS104757 for ; Mon, 27 May 2019 06:16:56 -0400 Received: from e11.ny.us.ibm.com (e11.ny.us.ibm.com [129.33.205.201]) by mx0a-001b2d01.pphosted.com with ESMTP id 2srcf3wfm3-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 27 May 2019 06:16:56 -0400 Received: from localhost by e11.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 27 May 2019 11:16:55 +0100 Received: from b01cxnp22033.gho.pok.ibm.com (9.57.198.23) by e11.ny.us.ibm.com (146.89.104.198) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 27 May 2019 11:16:48 +0100 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x4RAFWrv38928602 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 May 2019 10:15:33 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DFDC9B2065; Mon, 27 May 2019 10:15:32 +0000 (GMT) Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A8833B205F; Mon, 27 May 2019 10:15:32 +0000 (GMT) Received: from paulmck-ThinkPad-W541 (unknown [9.80.199.73]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP; Mon, 27 May 2019 10:15:32 +0000 (GMT) Received: by paulmck-ThinkPad-W541 (Postfix, from userid 1000) id 482C916C3573; Mon, 27 May 2019 03:15:36 -0700 (PDT) Date: Mon, 27 May 2019 03:15:36 -0700 From: "Paul E. McKenney" To: "Huang, Ying" Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Hugh Dickins , Minchan Kim , Johannes Weiner , Tim Chen , Mel Gorman , =?iso-8859-1?B?Suly9G1l?= Glisse , Michal Hocko , Andrea Arcangeli , Yang Shi , David Rientjes , Rik van Riel , Jan Kara , Dave Jiang , Daniel Jordan , Andrea Parri Subject: Re: [PATCH -mm] mm, swap: Simplify total_swapcache_pages() with get_swap_device() Reply-To: paulmck@linux.ibm.com References: <20190527082714.12151-1-ying.huang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190527082714.12151-1-ying.huang@intel.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 x-cbid: 19052710-2213-0000-0000-000003965E56 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00011171; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000286; SDB=6.01209261; UDB=6.00635237; IPR=6.00990287; MB=3.00027069; MTD=3.00000008; XFM=3.00000015; UTC=2019-05-27 10:16:53 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19052710-2214-0000-0000-00005E99536B Message-Id: <20190527101536.GI28207@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-05-27_07:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1905270073 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 27, 2019 at 04:27:14PM +0800, Huang, Ying wrote: > From: Huang Ying > > total_swapcache_pages() may race with swapper_spaces[] allocation and > freeing. Previously, this is protected with a swapper_spaces[] > specific RCU mechanism. To simplify the logic/code complexity, it is > replaced with get/put_swap_device(). The code line number is reduced > too. Although not so important, the swapoff() performance improves > too because one synchronize_rcu() call during swapoff() is deleted. I am guessing that total_swapcache_pages() is not used on any fastpaths, but must defer to others on this. Of course, if the performance/scalability of total_swapcache_pages() is important, benchmarking is needed. But where do I find get_swap_device() and put_swap_device()? I do not see them in current mainline. Thanx, Paul > Signed-off-by: "Huang, Ying" > Cc: Hugh Dickins > Cc: Paul E. McKenney > Cc: Minchan Kim > Cc: Johannes Weiner > Cc: Tim Chen > Cc: Mel Gorman > Cc: J?r?me Glisse > Cc: Michal Hocko > Cc: Andrea Arcangeli > Cc: Yang Shi > Cc: David Rientjes > Cc: Rik van Riel > Cc: Jan Kara > Cc: Dave Jiang > Cc: Daniel Jordan > Cc: Andrea Parri > --- > mm/swap_state.c | 28 ++++++++++------------------ > 1 file changed, 10 insertions(+), 18 deletions(-) > > diff --git a/mm/swap_state.c b/mm/swap_state.c > index f509cdaa81b1..b84c58b572ca 100644 > --- a/mm/swap_state.c > +++ b/mm/swap_state.c > @@ -73,23 +73,19 @@ unsigned long total_swapcache_pages(void) > unsigned int i, j, nr; > unsigned long ret = 0; > struct address_space *spaces; > + struct swap_info_struct *si; > > - rcu_read_lock(); > for (i = 0; i < MAX_SWAPFILES; i++) { > - /* > - * The corresponding entries in nr_swapper_spaces and > - * swapper_spaces will be reused only after at least > - * one grace period. So it is impossible for them > - * belongs to different usage. > - */ > - nr = nr_swapper_spaces[i]; > - spaces = rcu_dereference(swapper_spaces[i]); > - if (!nr || !spaces) > + /* Prevent swapoff to free swapper_spaces */ > + si = get_swap_device(swp_entry(i, 1)); > + if (!si) > continue; > + nr = nr_swapper_spaces[i]; > + spaces = swapper_spaces[i]; > for (j = 0; j < nr; j++) > ret += spaces[j].nrpages; > + put_swap_device(si); > } > - rcu_read_unlock(); > return ret; > } > > @@ -611,20 +607,16 @@ int init_swap_address_space(unsigned int type, unsigned long nr_pages) > mapping_set_no_writeback_tags(space); > } > nr_swapper_spaces[type] = nr; > - rcu_assign_pointer(swapper_spaces[type], spaces); > + swapper_spaces[type] = spaces; > > return 0; > } > > void exit_swap_address_space(unsigned int type) > { > - struct address_space *spaces; > - > - spaces = swapper_spaces[type]; > + kvfree(swapper_spaces[type]); > nr_swapper_spaces[type] = 0; > - rcu_assign_pointer(swapper_spaces[type], NULL); > - synchronize_rcu(); > - kvfree(spaces); > + swapper_spaces[type] = NULL; > } > > static inline void swap_ra_clamp_pfn(struct vm_area_struct *vma, > -- > 2.20.1 >