Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5650748ybi; Tue, 4 Jun 2019 09:49:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqySp8XagmxbG6K5X73t29GCliOwpzrTT+p22FfE2bXND1Gx6XEBppmU7G/IXfQgHlFh1m1L X-Received: by 2002:a17:902:ba88:: with SMTP id k8mr30671809pls.196.1559666968878; Tue, 04 Jun 2019 09:49:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559666968; cv=none; d=google.com; s=arc-20160816; b=kSbnwoV3t8SwQKsa6bv7wRWSXZFabY08nS7ZZtMNBVUFmfIE5z04QEFs9/TGy+ZarQ j3lkC3Y6AjUQbzxIeFTV/owURzzr2roxX//1qsFd7fpnyMysXGY++Cq9Y6d6qtt4nTtW 7W/HL48DUjo/BmBV4WJnGM5po3LHt23R5Ek5xIMSRD7VjI5l6TnbH/49zKqVHXJUl+wc WAFPKmTI19FA1QMQrE4Bi8kBSLU16O07gUpbnu3IebhfzM15WPk7GzzMq0RHuFlPIK2A xJhuU6Tyma9d7VS2VCYzlgO+dCmhR8paq1cW65sevPXXKjcTmbxfSQkgu56dT3J+Svqp sW6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=3RVoF1MXiXuJ49Ze8MqtY7JBy4Fets813n9NzKPP+sg=; b=X+/UHkUYWxjtVEqUfPE4I4iqT/ZvkHRL9XhbTjxDyEHbEEPftBGZoMz0e/Nxf8ZI4w IYNClzYhlsnq0XeydX0Ct5ZZquW/3WSpA7a/09ythUGO88xXEleKLwhcsWdBLVuSUD2z 4iO3yXFgM9lhwurD4bZrNtJkilrPaER6rk3mKG00TDn26eB2Ni5nMdiPbsDU3WFCcIaS 7jr1s7GZY/tQOtwdrLOMPaW/Dir6/HTcdyDcLZIec28abioMCBCfGfwBDh3aOGvw1HXq Zk7kSJXQ0ku+/XVGhRsm5DJ5IA4tBNWPbILWp6nskj2wzpwWPiBO7m+tt4KUDTAlb3Q0 e6hw== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t4si4149718pjo.24.2019.06.04.09.49.13; Tue, 04 Jun 2019 09:49:28 -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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727890AbfFDQrJ (ORCPT + 99 others); Tue, 4 Jun 2019 12:47:09 -0400 Received: from mga14.intel.com ([192.55.52.115]:37263 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727470AbfFDQrJ (ORCPT ); Tue, 4 Jun 2019 12:47:09 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Jun 2019 09:47:08 -0700 X-ExtLoop1: 1 Received: from iweiny-desk2.sc.intel.com ([10.3.52.157]) by fmsmga004.fm.intel.com with ESMTP; 04 Jun 2019 09:47:08 -0700 From: ira.weiny@intel.com To: Andrew Morton , Michal Hocko Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, John Hubbard , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , Dan Williams , Ira Weiny Subject: [PATCH v3] mm/swap: Fix release_pages() when releasing devmap pages Date: Tue, 4 Jun 2019 09:48:13 -0700 Message-Id: <20190604164813.31514-1-ira.weiny@intel.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ira Weiny release_pages() is an optimized version of a loop around put_page(). Unfortunately for devmap pages the logic is not entirely correct in release_pages(). This is because device pages can be more than type MEMORY_DEVICE_PUBLIC. There are in fact 4 types, private, public, FS DAX, and PCI P2PDMA. Some of these have specific needs to "put" the page while others do not. This logic to handle any special needs is contained in put_devmap_managed_page(). Therefore all devmap pages should be processed by this function where we can contain the correct logic for a page put. Handle all device type pages within release_pages() by calling put_devmap_managed_page() on all devmap pages. If put_devmap_managed_page() returns true the page has been put and we continue with the next page. A false return of put_devmap_managed_page() means the page did not require special processing and should fall to "normal" processing. This was found via code inspection while determining if release_pages() and the new put_user_pages() could be interchangeable.[1] [1] https://lore.kernel.org/lkml/20190523172852.GA27175@iweiny-DESK2.sc.intel.com/ Cc: Jérôme Glisse Cc: Michal Hocko Reviewed-by: Dan Williams Reviewed-by: John Hubbard Signed-off-by: Ira Weiny --- Changes from V2: Update changelog for more clarity as requested by Michal Update comment WRT "failing" of put_devmap_managed_page() Changes from V1: Add comment clarifying that put_devmap_managed_page() can still fail. Add Reviewed-by tags. mm/swap.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mm/swap.c b/mm/swap.c index 7ede3eddc12a..6d153ce4cb8c 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -740,15 +740,20 @@ void release_pages(struct page **pages, int nr) if (is_huge_zero_page(page)) continue; - /* Device public page can not be huge page */ - if (is_device_public_page(page)) { + if (is_zone_device_page(page)) { if (locked_pgdat) { spin_unlock_irqrestore(&locked_pgdat->lru_lock, flags); locked_pgdat = NULL; } - put_devmap_managed_page(page); - continue; + /* + * Not all zone-device-pages require special + * processing. Those pages return 'false' from + * put_devmap_managed_page() expecting a call to + * put_page_testzero() + */ + if (put_devmap_managed_page(page)) + continue; } page = compound_head(page); -- 2.20.1