Received: by 10.223.176.5 with SMTP id f5csp4257103wra; Tue, 30 Jan 2018 04:40:15 -0800 (PST) X-Google-Smtp-Source: AH8x226SUrneM4u2rsvfUR0U7tz9IwOQsqLoY0eMSAkQM4GTSI9SXJNwhbMneGpyM1mRKuHH0F6p X-Received: by 10.98.15.27 with SMTP id x27mr30699097pfi.197.1517316015745; Tue, 30 Jan 2018 04:40:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517316015; cv=none; d=google.com; s=arc-20160816; b=vaje7RJ00o2OZakr5ikGFBMsQbaC1daHQ5pTslOXTR6gNMueilWanN/bFhFD+ZMHyn IKNe6UIcj9rDx2JdU1M1HVd3rpyxx//IXNGjbfm3G+n+88z6BFoniFMWnj/LpFfpR4uh y86LfEhmmf8RjsvuH3fK0g8x5kLxgWIJQJhK/k13wBSR9BGng2F4+H7Lot4+jZ+PltX2 QrrZ7P7PEbChYcYwafHaC9Z5XNgZQZmE2hbqRnDbkCjLkgUV5Ju+bJbYANA5T5w24IWc X+BXqNf+zG/O4ikg8kHftpXDbxs08qFMZcIBvvN1f9IKJEykZxnobpQ7R7SQgK9PuULu nu2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date :arc-authentication-results; bh=f8xALLKkbz1l1mZ0LQfyNu+EQf+jfG4wbSspFX+GVB4=; b=wDlAqxNGyU5sbLCfMagzRYKfHfJpVRTY//0WxmGMq+oTApaAqsnvgEOpeQPinXMU6a o2dEC9fzpP1qQLmM/u8L4brwiXD/dSuUnZ8wKnCEmpMHTxoXP40CmVZFa7bsAuXgFQob uvvzH4+xlJonwtiOFIkRvhe/3ooimTk7CEWN/GsvylfQdehPo7BVvJWh63lk2k/gHSjY PYM5x/mUDle7FdYeOO9g+LUaLHVI75PAb5FA/Le5MCIzBbjx/TygOa3P9A0vl3Pu92RE DHa/FZWzxotW1VCeRwU1VZre9XkYvpvnJzZTTmRcP/f9XEZiOUP2CPExIDU55+UKK4pa i+LQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e4si9177511pgs.271.2018.01.30.04.40.01; Tue, 30 Jan 2018 04:40:15 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751914AbeA3M24 (ORCPT + 99 others); Tue, 30 Jan 2018 07:28:56 -0500 Received: from mx2.suse.de ([195.135.220.15]:55464 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751715AbeA3M2z (ORCPT ); Tue, 30 Jan 2018 07:28:55 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id CFFD3AE1C; Tue, 30 Jan 2018 12:28:53 +0000 (UTC) Date: Tue, 30 Jan 2018 13:28:53 +0100 From: Michal Hocko To: Christian =?iso-8859-1?Q?K=F6nig?= Cc: "He, Roger" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , "dri-devel@lists.freedesktop.org" Subject: Re: [PATCH] mm/swap: add function get_total_swap_pages to expose total_swap_pages Message-ID: <20180130122853.GC21609@dhcp22.suse.cz> References: <1517214582-30880-1-git-send-email-Hongbo.He@amd.com> <20180129163114.GH21609@dhcp22.suse.cz> <20180130075553.GM21609@dhcp22.suse.cz> <9060281e-62dd-8775-2903-339ff836b436@amd.com> <20180130101823.GX21609@dhcp22.suse.cz> <7d5ce7ab-d16d-36bc-7953-e1da2db350bf@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <7d5ce7ab-d16d-36bc-7953-e1da2db350bf@amd.com> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 30-01-18 11:32:49, Christian K?nig wrote: > Am 30.01.2018 um 11:18 schrieb Michal Hocko: > > On Tue 30-01-18 10:00:07, Christian K?nig wrote: > > > Am 30.01.2018 um 08:55 schrieb Michal Hocko: > > > > On Tue 30-01-18 02:56:51, He, Roger wrote: > > > > > Hi Michal: > > > > > > > > > > We need a API to tell TTM module the system totally has how many swap > > > > > cache. Then TTM module can use it to restrict how many the swap cache > > > > > it can use to prevent triggering OOM. For Now we set the threshold of > > > > > swap size TTM used as 1/2 * total size and leave the rest for others > > > > > use. > > > > Why do you so much memory? Are you going to use TB of memory on large > > > > systems? What about memory hotplug when the memory is added/released? > > > For graphics and compute applications on GPUs it isn't unusual to use large > > > amounts of system memory. > > > > > > Our standard policy in TTM is to allow 50% of system memory to be pinned for > > > use with GPUs (the hardware can't do page faults). > > > > > > When that limit is exceeded (or the shrinker callbacks tell us to make room) > > > we wait for any GPU work to finish and copy buffer content into a shmem > > > file. > > > > > > This copy into a shmem file can easily trigger the OOM killer if there isn't > > > any swap space left and that is something we want to avoid. > > > > > > So what we want to do is to apply this 50% rule to swap space as well and > > > deny allocation of buffer objects when it is exceeded. > > How does that help when the rest of the system might eat swap? > > Well it doesn't, but that is not the problem here. > > When an application keeps calling malloc() it sooner or later is confronted > with an OOM killer. > > But when it keeps for example allocating OpenGL textures the expectation is > that this sooner or later starts to fail because we run out of memory and > not trigger the OOM killer. There is nothing like running out of memory and not triggering the OOM killer. You can make a _particular_ allocation to bail out without the oom killer. Just use __GFP_NORETRY. But that doesn't make much difference when you have already depleted your memory and live with the bare remainings. Any desperate soul trying to get its memory will simply trigger the OOM. > So what we do is to allow the application to use all of video memory + a > certain amount of system memory + swap space as last resort fallback (e.g. > when you Alt+Tab from your full screen game back to your browser). > > The problem we try to solve is that we haven't limited the use of swap space > somehow. I do think you should completely ignore the size of the swap space. IMHO you should forbid further allocations when your current buffer storage cannot be reclaimed. So you need some form of feedback mechanism that would tell you: "Your buffers have grown too much". If you cannot do that then simply assume that you cannot swap at all rather than rely on having some portion of it for yourself. There are many other users of memory outside of your subsystem. Any scaling based on the 50% of resource belonging to me is simply broken. -- Michal Hocko SUSE Labs