From patchwork Fri Jul 20 07:18:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 10536061 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3D82460547 for ; Fri, 20 Jul 2018 07:20:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 290B82986B for ; Fri, 20 Jul 2018 07:20:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1CA5629868; Fri, 20 Jul 2018 07:20:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B5E8928610 for ; Fri, 20 Jul 2018 07:20:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0F7A06B000D; Fri, 20 Jul 2018 03:20:01 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0A7BA6B000E; Fri, 20 Jul 2018 03:20:01 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E63AB6B0010; Fri, 20 Jul 2018 03:20:00 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by kanga.kvack.org (Postfix) with ESMTP id A0AB16B000D for ; Fri, 20 Jul 2018 03:20:00 -0400 (EDT) Received: by mail-pg1-f200.google.com with SMTP id g5-v6so5390039pgq.5 for ; Fri, 20 Jul 2018 00:20:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=k/qyG509/ytJi+PMQfl0YKN0q1FCv6cRuiP1uC7Iw78=; b=F/yhz07EqLM2SYWdkmjDzDCBkLO7HH7+X2NmyQeymr9mEMH38nxzW2vJnBtSfS/63H 57Nb6mu0C8cl3632+rQNF9GLmE5fWjdyJyGxeXlHIjCY7q//qGJLrT7bcqHU+rOEC+Zf 32b//r/8pelKIN5kTTWZ+evHOQ1SLv+5mqpoCyu79Vwo+gUicQafQft4gLbujxBmY0TQ /f50IfOt3LKZ74eiEvkgvYxkRNuE+8Z9rNpC3Lbz4E4YQPUN0yXgk6vWtg81j1xh1/un lznfY8kbLv1WdQ1kmLLie1NR19UjZJ+AzlArq1PuroV+EnfOrCF+CJ3x9aZgQtqbPyQG S/QA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: AOUpUlFRUfejfXHiBcWWJPCrj9qXDvhNEkrzkvmiTQZks8rq00NTOtIA dmDyrv5qAVepg6zit1Xn487qn2ifjHFQ4nqcbBYFgCpLuJVraJxMmxvCNWfd/dyWqMGYqumwa3w RuPyfaFJzIVA6r7L2bvEFSdpj+IYIOddQjHF67unDZGEusgC5klw0gatMx0KOYMJdLg== X-Received: by 2002:a62:4ece:: with SMTP id c197-v6mr1034289pfb.240.1532071200357; Fri, 20 Jul 2018 00:20:00 -0700 (PDT) X-Google-Smtp-Source: AAOMgpexsQ3y9uBIRLT/6SMyz9zAiymZZAnI67QVEabTWDUS2swnrL8bZSWTx3/8If63LJYdV29q X-Received: by 2002:a62:4ece:: with SMTP id c197-v6mr1034259pfb.240.1532071199710; Fri, 20 Jul 2018 00:19:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532071199; cv=none; d=google.com; s=arc-20160816; b=Dm4wffRvwOLdMziFVq6+j86tTKvrfjQFs3xU+RVPWNPTzicrtGVBTcWkFU1Yxp0Zky VnYi3CVfeeiLra5cWEWLLSisSqq3RKbCspOTLIiVOBBjMmIDSiKKpfXh0arftdrb00gw 8pkCgD2nx0hRwo5sayE8v8BtNOJhQPXyOxvasYSipUI2ixsU0tjRWv3K5jrVIfchdJpL NAzBGG3Oa+0hdeyktHCsqJ2u2qdKwEqWLf89h3ik3jMOJJjzktNyij64fi0q56FCuqp7 EnYOw4RujbOYXjpuprZofgyiS/Fmixl0e4bytIrCSqbmxyRB0lIRe1lGWrb8EILUlf8O Ywqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=k/qyG509/ytJi+PMQfl0YKN0q1FCv6cRuiP1uC7Iw78=; b=DPtYLRIX2NUnF/Quw/8lDR1JGHpfDMHPOKdKTJhJooAGgeKbbwDvMxw6LclzQilHw8 P6/gBZoAL+bDHY8rw3uZlOANU+OfUzXK2jZE9So3J5BtHEJ/rMs/mH/nNQG1C0rQB/mr X5q3GYfGyfsYWiOeImH9SZ1h8bwSDM7TeGGI+pSAiQ3r8VwkUI9tm4mljObZ9Zpaukoq I/Z/gcu+8pgznZJDxSJb+LZpLhZdhyEjfEpUNQX5INlMkG1HF2bBkmYA7Ld6b/Ymm7I6 QpwF7GNdQCEq0ebXR9rtoYA/JBJolnSYtmaE8PrykVtIJ3bI8uZ5YrlNWiB55vJ7xd66 jGug== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga07.intel.com (mga07.intel.com. [134.134.136.100]) by mx.google.com with ESMTPS id a18-v6si1135668plm.122.2018.07.20.00.19.59 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 20 Jul 2018 00:19:59 -0700 (PDT) Received-SPF: pass (google.com: domain of ying.huang@intel.com designates 134.134.136.100 as permitted sender) client-ip=134.134.136.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Jul 2018 00:19:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,377,1526367600"; d="scan'208";a="68652059" Received: from yhuang6-ux31a.sh.intel.com ([10.239.198.6]) by fmsmga002.fm.intel.com with ESMTP; 20 Jul 2018 00:19:07 -0700 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , Michal Hocko , Johannes Weiner , Shaohua Li , Hugh Dickins , Minchan Kim , Rik van Riel , Dan Williams , Daniel Jordan , Dave Hansen Subject: [PATCH v4 7/8] swap: Add __swap_entry_free_locked() Date: Fri, 20 Jul 2018 15:18:44 +0800 Message-Id: <20180720071845.17920-8-ying.huang@intel.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180720071845.17920-1-ying.huang@intel.com> References: <20180720071845.17920-1-ying.huang@intel.com> 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: X-Virus-Scanned: ClamAV using ClamSMTP The part of __swap_entry_free() with lock held is separated into a new function __swap_entry_free_locked(). Because we want to reuse that piece of code in some other places. Just mechanical code refactoring, there is no any functional change in this function. Signed-off-by: "Huang, Ying" Reviewed-by: Daniel Jordan Acked-by: Dave Hansen Cc: Michal Hocko Cc: Johannes Weiner Cc: Shaohua Li Cc: Hugh Dickins Cc: Minchan Kim Cc: Rik van Riel Cc: Dan Williams --- mm/swapfile.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index d80567dd60db..402d52ff3e4a 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1182,16 +1182,13 @@ struct swap_info_struct *get_swap_device(swp_entry_t entry) return NULL; } -static unsigned char __swap_entry_free(struct swap_info_struct *p, - swp_entry_t entry, unsigned char usage) +static unsigned char __swap_entry_free_locked(struct swap_info_struct *p, + unsigned long offset, + unsigned char usage) { - struct swap_cluster_info *ci; - unsigned long offset = swp_offset(entry); unsigned char count; unsigned char has_cache; - ci = lock_cluster_or_swap_info(p, offset); - count = p->swap_map[offset]; has_cache = count & SWAP_HAS_CACHE; @@ -1219,6 +1216,17 @@ static unsigned char __swap_entry_free(struct swap_info_struct *p, usage = count | has_cache; p->swap_map[offset] = usage ? : SWAP_HAS_CACHE; + return usage; +} + +static unsigned char __swap_entry_free(struct swap_info_struct *p, + swp_entry_t entry, unsigned char usage) +{ + struct swap_cluster_info *ci; + unsigned long offset = swp_offset(entry); + + ci = lock_cluster_or_swap_info(p, offset); + usage = __swap_entry_free_locked(p, offset, usage); unlock_cluster_or_swap_info(p, ci); return usage;