Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp872571ybt; Wed, 24 Jun 2020 13:26:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyObVYE9Jz5mS1u/WR20kFySxN/GWx7U0frUlkkuPSkKyGUWye6yjFzNZSGuqNiT7082OMp X-Received: by 2002:a17:906:3745:: with SMTP id e5mr26790584ejc.19.1593030386006; Wed, 24 Jun 2020 13:26:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593030386; cv=none; d=google.com; s=arc-20160816; b=V1i2qDo4+XuX5opqsyqs3zLTOQlbwvluoFwsGfwjhvL5KdD0jdys9iZNOI2Kyq8pfk M4b+vNMOygd5L0MmyxN8M8nSQzoaPKlz1Y+N1lGW6GeF6B57mOj6YpMUN0Jkg3T9wjc+ BhsxfIIWwqPkRet/ZF9WFlEZ0LL3KIRdxcu3PrZ5YjTTIV7MU+zmCrYwxWa/GnHbNpYU +7X8SRsvBvJL6BTubYyOUFHkR5yO4OQBC2dugNZ+7p2fQZYrzwyXIZAUxP7eAfswF9Hs /vmUA8x7obaE8G7bCAKph+dSUF+lqS1py8aGj2j7Uvu6w8AHZkCAHJZfLXypG0Npla6N Wb8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=3N8Iq+jMa7Wr2bmXCR98pNboSajMlgVPuPMQP9CFTnI=; b=kPouHVt6eaydCjar4JegN0lvvOr6WrVXVlV/SsZ06BE4xvyHH6HszacjAGtU51HJbe p0BRpAhrzMxsqQUEWJEIggOq8eix0zzN8S8cblDiXLerS+x1Gy4ZFgo3cxpAmn0W3wFj EelznduzLRHKE5NQO86g02Dj0AHLh5o8WMrpIj+xBRfEtyt2G7Df6T0MI0q9lHAX8TD7 EwrxQ8SUrb/7glHn++f6WTuBkD/acOaZuOnKG0jIUZvop9aOBvxwWxxiTcRwQ84AAIM8 n8S36ftXgjVGBlExsvwNXlkSjK7oOP63+97XL1TZ2vjME0KQjL2xjPyXy7sQPx4zvIgq aCtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gsLANbH8; 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 h9si14825492edf.128.2020.06.24.13.26.01; Wed, 24 Jun 2020 13:26:25 -0700 (PDT) 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=gsLANbH8; 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 S2406390AbgFXUXR (ORCPT + 99 others); Wed, 24 Jun 2020 16:23:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406361AbgFXUXQ (ORCPT ); Wed, 24 Jun 2020 16:23:16 -0400 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB3F0C061573 for ; Wed, 24 Jun 2020 13:23:15 -0700 (PDT) Received: by mail-ej1-x642.google.com with SMTP id ga4so3709798ejb.11 for ; Wed, 24 Jun 2020 13:23:15 -0700 (PDT) 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=3N8Iq+jMa7Wr2bmXCR98pNboSajMlgVPuPMQP9CFTnI=; b=gsLANbH8oUM6Oqn4g+49U/gczDfj3IaDXZ4bdqAM970FR1Kzectrc0SAtNLpsQY0LF JrlPKLo+goWwEjS3lM+M4CiRFku+WAyJCHeZKt8JxtukWcMI1AlskIDY8bRU6xfll5JQ XEvJ7WrIDuTPmB/Q+e3RtTXXOV9jZMPybKMGzBGZdgkOAofL1rY6yrLx0AkYkFvl0LrR vM55HjIBf9SnCeu26+5a4DmCplfZH797uDptMTtp7UwjTGM0qKFaPsGMDtD83p29fAPd g/7B9Efx/ARDqWtNzohLVDa6iG/gtZ4PBo3rSCtCXq7uMEp+BNPAZ167Fdm/Z/uvTmum NzAg== 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=3N8Iq+jMa7Wr2bmXCR98pNboSajMlgVPuPMQP9CFTnI=; b=n0BEVNZy1nmIEmhepSYbjotKKV77P47jwycWVvh7R852Hz/Tk6pFt30kvxEB34CLTF IlwanySl0ekjib2Q9eOx9pf9/wQFaOdlo7zZIrSOxgzy0A0ocK1dKqsqd3/Td54V8tz8 +RUJ947JQJ2eRsLBg8A28bP3I1q2btVPnwXO1TbbuToKEJm1Alxnw7hq2FhcBZfvQR6W mWctSVq4eyQMX9wDdUIZeeDkupTA5avgy2c0QT7WPuEZ0OVS+gkoPl5mrAaGzID+eY8y /QWcnHMbtNrJKXOfKGi+el1cUvzEZLz8hZS7PF4ThDNyhWT4x/6ek8WNToMZY+hwKoHX dV+A== X-Gm-Message-State: AOAM532pDMTTQx2Z5k39bXovAUPKQzm8dkk+nM+M5Hm1FYhzBkIBTkOd qkhzVPCvdo9MZ/PdUuf896LxgBVoDOFbW9gpQ0o= X-Received: by 2002:a17:907:2058:: with SMTP id pg24mr18819307ejb.79.1593030194663; Wed, 24 Jun 2020 13:23:14 -0700 (PDT) MIME-Version: 1.0 References: <20200624191417.16735-1-chris@chris-wilson.co.uk> <20200624192116.GO6578@ziepe.ca> In-Reply-To: <20200624192116.GO6578@ziepe.ca> From: Yang Shi Date: Wed, 24 Jun 2020 13:23:02 -0700 Message-ID: Subject: Re: [PATCH] mm: Skip opportunistic reclaim for dma pinned pages To: Jason Gunthorpe Cc: Chris Wilson , Linux MM , Linux Kernel Mailing List , intel-gfx@lists.freedesktop.org, Andrew Morton , Jan Kara , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , John Hubbard , Claudio Imbrenda , "Kirill A . Shutemov" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 24, 2020 at 12:21 PM Jason Gunthorpe wrote: > > On Wed, Jun 24, 2020 at 08:14:17PM +0100, Chris Wilson wrote: > > A general rule of thumb is that shrinkers should be fast and effective. > > They are called from direct reclaim at the most incovenient of times when > > the caller is waiting for a page. If we attempt to reclaim a page being > > pinned for active dma [pin_user_pages()], we will incur far greater > > latency than a normal anonymous page mapped multiple times. Worse the > > page may be in use indefinitely by the HW and unable to be reclaimed > > in a timely manner. > > A pinned page can't be migrated, discarded or swapped by definition - > it would cause data corruption. > > So, how do things even get here and/or work today at all? I think the > explanation is missing something important. The __remove_mapping() will try to freeze page count if the count is expected otherwise just not discard the page. I'm not quite sure why the check is done that late, my wild guess is to check the refcount at the last minute so there might be a chance the pin gets released right before it. But I noticed a bug in __remove_ampping() for THP since THP's dma pinned count is recorded in the tail page's hpage_pinned_refcount instead of refcount. So, the refcount freeze might be successful for pinned THP. Chris's patch could solve this issue too, but I'm not sure if it is worth backing earlier once dma pinned page is met. If it is worth, the follow-up question is why not just skip such page in scan phase? > > Jason >