From patchwork Mon Sep 3 07:21:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 10585555 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 61EDB14BD for ; Mon, 3 Sep 2018 07:22:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4BEE129189 for ; Mon, 3 Sep 2018 07:22:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4040F2956E; Mon, 3 Sep 2018 07:22:41 +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=ham 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 B085829189 for ; Mon, 3 Sep 2018 07:22:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C6B116B66AD; Mon, 3 Sep 2018 03:22:35 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BED856B66AC; Mon, 3 Sep 2018 03:22:35 -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 ADC6D6B66AD; Mon, 3 Sep 2018 03:22:35 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) by kanga.kvack.org (Postfix) with ESMTP id 715156B66A9 for ; Mon, 3 Sep 2018 03:22:35 -0400 (EDT) Received: by mail-pf1-f200.google.com with SMTP id q21-v6so10804204pff.21 for ; Mon, 03 Sep 2018 00:22:35 -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=3/zbj882JM1io85kkkLx0aDHDlHkhXjaPs/vQA4jdIs=; b=coQ9sdF5e3Vn9rtcZ+JycVpJ121IYXg/9B4sUMZQxunH5Je8fzAG346+tNbs1W7rse 7fGXSWQ0zMVGeYlz6DnIQzR2qSVn22Z//eO0in5gJLNqyaZ8mvmss+QECXQMxMLy9QK+ YKyTLxZrDTKHM5SWowCiHnQGPES3u5SoqHqialakPhMZZBdyU77g1GqVX9Gu+cCCGb4p JrVlxaY054MCvHZssyfWT8Oz2APzmy/CaLyrQPNX2DsjwjKlOm5CTsbR9OYF2fibxdkQ ctCAaMYxJkEMm2hchx4z7YKOAXJ/JMDGjjEyqeHyU23WoA9sFunX4gprPptNjVY+2z1z oyhw== 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: APzg51C9tuONULv6Bsz2zmViGWvleCBNtGnTN4lh6AUW0cMLkPwjdyMZ 9VSBtdbqENKxiFTRZ96PRINzJerbjhq6bO674p3M3oB7iY33fE885BMu1ZfO/sy4pwybgEGSyIB 7CiSLgB6+bxW8NXYlb9dOzCVM92SBadoZ1rYPp6gJS6U10d6H4CQwzuDVPM72m18drA== X-Received: by 2002:a65:448a:: with SMTP id l10-v6mr25355422pgq.382.1535959355138; Mon, 03 Sep 2018 00:22:35 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYwAqf01OR9Jf8fytfzGbXTMnxCMrTFbbrSlNXdYYpoxxe2N8PZikuP1mVgsNk4kt6Mzy+Z X-Received: by 2002:a65:448a:: with SMTP id l10-v6mr25355388pgq.382.1535959354389; Mon, 03 Sep 2018 00:22:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535959354; cv=none; d=google.com; s=arc-20160816; b=pyfCf6EYQkQlSLkMSwmTgFAo8m3EvSSOnM1UR4SrPCcGSAPuq0Dk6RkbpDzgyCTByo nuQ7IJD41HhuWWtnsaVRIB9JwqwIAK3OeiAozksbBd+J9TPo58dymePaRs/YUSPKCopi dswKcuEBZdVHCtHY/n16zxMxV6Gprtz/rfCyYjziRpVZyAogFxVvrM3BWXcPcfrkzFQP RD5fvfCqTRNjJdZ6n45m5aePOo9b8besFstg51SyCoIz6PJx1FPL0iQ9fdOuv2jAM00r obYnxrZsryMDc5LpTWuWs8qQpRFmr/f954Iw4CConrYMfvoVgbwe/C+J4SBdeubogUT4 7AOQ== 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=3/zbj882JM1io85kkkLx0aDHDlHkhXjaPs/vQA4jdIs=; b=VwqrVqH5lLhCi9ka9dGicP2A3RcEnFnBSY5v0HVh3BBZ9kBecC4NmgzD6LXKQqW8HP 0pcP42sgaomlAOWqRnzzIav2SkbAfI1GZpb1t2hbyIIBEyLifIAhm1xfluX0H/xkd/Bf DTtGV89fCxZ7G9qXnqcDZeJuJze3Z7AgaiGBFpyL5GgL73Qjj/Ob+RW4S/BUJ/4taM4r EultkL84vLXJzAzE34vHOHquEeYWEyynDsH5GlqyL8NCqvQTRfHIgPczsc319H0mlEmS 2rTtkKOGivDhXs0XZjBBSgY23RugVDx8Y1+aOX4GXSHl6dTCTNMz4QY0V4uq6dQV4j8e QTyg== 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 r24-v6si4679764pgg.403.2018.09.03.00.22.34 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Sep 2018 00:22:34 -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 orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Sep 2018 00:22:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,324,1531810800"; d="scan'208";a="70146861" Received: from yhuang-mobile.sh.intel.com ([10.239.196.86]) by orsmga008.jf.intel.com with ESMTP; 03 Sep 2018 00:22:17 -0700 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , "Kirill A. Shutemov" , Andrea Arcangeli , Michal Hocko , Johannes Weiner , Shaohua Li , Hugh Dickins , Minchan Kim , Rik van Riel , Dave Hansen , Naoya Horiguchi , Zi Yan , Daniel Jordan Subject: [PATCH -V5 02/21] swap: Add __swap_duplicate_locked() Date: Mon, 3 Sep 2018 15:21:55 +0800 Message-Id: <20180903072214.24602-3-ying.huang@intel.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180903072214.24602-1-ying.huang@intel.com> References: <20180903072214.24602-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_duplicate() with lock held is separated into a new function __swap_duplicate_locked(). Because we will add more logic about the PMD swap mapping into __swap_duplicate() and keep the most PTE swap mapping related logic in __swap_duplicate_locked(). Just mechanical code refactoring, there is no any functional change in this patch. Signed-off-by: "Huang, Ying" Cc: "Kirill A. Shutemov" Cc: Andrea Arcangeli Cc: Michal Hocko Cc: Johannes Weiner Cc: Shaohua Li Cc: Hugh Dickins Cc: Minchan Kim Cc: Rik van Riel Cc: Dave Hansen Cc: Naoya Horiguchi Cc: Zi Yan Cc: Daniel Jordan --- mm/swapfile.c | 63 +++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 1996dcd732b6..532de6f8ff39 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3436,32 +3436,12 @@ void si_swapinfo(struct sysinfo *val) spin_unlock(&swap_lock); } -/* - * Verify that a swap entry is valid and increment its swap map count. - * - * Returns error code in following case. - * - success -> 0 - * - swp_entry is invalid -> EINVAL - * - swp_entry is migration entry -> EINVAL - * - swap-cache reference is requested but there is already one. -> EEXIST - * - swap-cache reference is requested but the entry is not used. -> ENOENT - * - swap-mapped reference requested but needs continued swap count. -> ENOMEM - */ -static int __swap_duplicate(swp_entry_t entry, unsigned char usage) +static int __swap_duplicate_locked(struct swap_info_struct *p, + unsigned long offset, unsigned char usage) { - struct swap_info_struct *p; - struct swap_cluster_info *ci; - unsigned long offset; unsigned char count; unsigned char has_cache; - int err = -EINVAL; - - p = get_swap_device(entry); - if (!p) - goto out; - - offset = swp_offset(entry); - ci = lock_cluster_or_swap_info(p, offset); + int err = 0; count = p->swap_map[offset]; @@ -3471,12 +3451,11 @@ static int __swap_duplicate(swp_entry_t entry, unsigned char usage) */ if (unlikely(swap_count(count) == SWAP_MAP_BAD)) { err = -ENOENT; - goto unlock_out; + goto out; } has_cache = count & SWAP_HAS_CACHE; count &= ~SWAP_HAS_CACHE; - err = 0; if (usage == SWAP_HAS_CACHE) { @@ -3503,11 +3482,39 @@ static int __swap_duplicate(swp_entry_t entry, unsigned char usage) p->swap_map[offset] = count | has_cache; -unlock_out: +out: + return err; +} + +/* + * Verify that a swap entry is valid and increment its swap map count. + * + * Returns error code in following case. + * - success -> 0 + * - swp_entry is invalid -> EINVAL + * - swp_entry is migration entry -> EINVAL + * - swap-cache reference is requested but there is already one. -> EEXIST + * - swap-cache reference is requested but the entry is not used. -> ENOENT + * - swap-mapped reference requested but needs continued swap count. -> ENOMEM + */ +static int __swap_duplicate(swp_entry_t entry, unsigned char usage) +{ + struct swap_info_struct *p; + struct swap_cluster_info *ci; + unsigned long offset; + int err = -EINVAL; + + p = get_swap_device(entry); + if (!p) + goto out; + + offset = swp_offset(entry); + ci = lock_cluster_or_swap_info(p, offset); + err = __swap_duplicate_locked(p, offset, usage); unlock_cluster_or_swap_info(p, ci); + + put_swap_device(p); out: - if (p) - put_swap_device(p); return err; }