Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp684109pxf; Wed, 17 Mar 2021 13:22:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMXZWy8iWur868B/9S3y3IMa9k4QoTh1VAeVs+fA928aZH1uVg8mSZJczTYjfMDOnza65I X-Received: by 2002:a05:6402:2058:: with SMTP id bc24mr44802983edb.243.1616012526209; Wed, 17 Mar 2021 13:22:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616012526; cv=none; d=google.com; s=arc-20160816; b=XhHDCeiGOYOWyCuxjlrcC0rxZGTOhdH4kL1YyXkV5sb4QKkaW9UYLbiPRrj5hSidXX 1H7jZw0Rkgqou4Mmg9PhNbkhPQnFMv9vptNaBy/A1VnL/NacHry3we+m0dKloKdorlhh e+gEYHNMNYM6NsmZzocOXmXglBzfLMsfqwtoK709nJke4jjs5uZ/hTiSFyRXyMawspPl zMenPbica5ECCEDz7ZQe+zqKzbsbC9mqS9WuvdDVqPSvdtoPXYGJ/49c5ESaRyLI/7jF f69rQbKmKnOJvqkpQMs9ThuXf0zTbWS+iplL5g6+JC5ulWQgGyLrS0FtEkmXaFkXIcOz 2CQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=J6gJzCwpLyG7+14+e+3YoRVEedOSyoYsJ1d1aSm3u8s=; b=sg/dSEA/jJzs4gqzmmCyPN4XBU7tS9g7x6pZRpobEcGUuERxXGvgibtAPCqShFuonT aO5R8xcoUd7yCl8JYAEdHFXMavBocFwHQ//+4W29FLa93/Nb6zTlojcJdHkmyWq5AXsc Gio4YRjqTS9vFXrDOO9KmoVRczv+UO3E2NTjz58pCQxrbeL9YrXwYhaVR44WFuAPqR1s dfw4Cp4u1CyVJy7v18RI3/W/mjVqDRG/BUMcActx2qJj/Mgzok9LNhrYY3/Bo2HKDxB4 lj64XsKrtLLxuMoutegJkutxT/IBqUpQAMBHbWi2IFTyg/55t45+KrnXackGNaUO2DPW 9HZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Ot1J2LG0; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f19si16220170ejc.312.2021.03.17.13.21.42; Wed, 17 Mar 2021 13:22:06 -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=@google.com header.s=20161025 header.b=Ot1J2LG0; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233295AbhCQUSQ (ORCPT + 99 others); Wed, 17 Mar 2021 16:18:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233443AbhCQURr (ORCPT ); Wed, 17 Mar 2021 16:17:47 -0400 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF2EEC06174A for ; Wed, 17 Mar 2021 13:17:46 -0700 (PDT) Received: by mail-lj1-x232.google.com with SMTP id 16so4750288ljc.11 for ; Wed, 17 Mar 2021 13:17:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=J6gJzCwpLyG7+14+e+3YoRVEedOSyoYsJ1d1aSm3u8s=; b=Ot1J2LG0SujcfumGfz731vdJqKOxO4S52bTDK4ESl++y2B/qGrQJ3ZdY9Sabt4+qqD CzWxpMj1luRIBQBFf/hyxd2opLMAqV+cwP7dETj1336+AfgOqmHKYaS1AhWtahJVwqlU gN553b7yWZyHe+SWBQ9bi314J/UcXDnhrU4nma/KHf7eOaDPE89DCmyfYyjlFc58rtjR whkrzXuDb3CPlElVyu7jaeUhUnKX65xuboxd3rKb2tS8bX9WpDZFAgettshbfdbaKNHH u9gNjJ1sQ7q4evUHcE8LsEtu7/1CyNif50ADrZcWccijWbfuWsO0kK7olDowKVJPpK8j RYmg== 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=J6gJzCwpLyG7+14+e+3YoRVEedOSyoYsJ1d1aSm3u8s=; b=E8bconJw7AjQtQiymYcR+tkaRDoxOnHlyHZR+dfSR6R8raczgXcPf7lpyw7JGwxkRK u+8ZZIWh9ewPfxCjzgf2ei2XJQlGn+APafDK1U+OPKThy/T5jcI8zulBBO/EQbGxexBj 87aGk3qqGbbReYlPRD5Dqpnbfb+kkzrxfqiViF+p0+h2x1ovw3J0lMbKgyDciwnpylYe 1hMEzVC8E5ueU3XTEZNy8i9Guw9y0jfARSAFn9b967r1e/RBYOGYpMaieYamGMQrpFtC UYuIW4BPs3JsWbNblaPoctaN5i1s8i5JVnydUBiM0JErvyJNPWzdnmJr2fda+XNVp8t3 2Ygw== X-Gm-Message-State: AOAM531cgDuY0necgg5qOu2MHuOpYPkbGuwp5rDg3fJ9ZdkbXuF4voJo Fx8bfNUzkeLAuIVHdxZigQKsfWs9GMYfiiGvhrK2JQ== X-Received: by 2002:a2e:b6d4:: with SMTP id m20mr3432836ljo.448.1616012265057; Wed, 17 Mar 2021 13:17:45 -0700 (PDT) MIME-Version: 1.0 References: <20210316011630.1121213-1-dualli@chromium.org> <20210317180048.inzdursqmnvxkgwp@wittgenstein> In-Reply-To: <20210317180048.inzdursqmnvxkgwp@wittgenstein> From: Jann Horn Date: Wed, 17 Mar 2021 21:17:18 +0100 Message-ID: Subject: Re: [PATCH v3 0/3] Binder: Enable App Freezing Capability To: Christian Brauner Cc: Li Li , dualli@google.com, Todd Kjos , Greg Kroah-Hartman , Christian Brauner , =?UTF-8?B?QXJ2ZSBIasO4bm5ldsOlZw==?= , "open list:ANDROID DRIVERS" , kernel list , Martijn Coenen , Hridya Valsaraju , Suren Baghdasaryan , "Joel Fernandes (Google)" , kernel-team Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 17, 2021 at 7:00 PM Christian Brauner wrote: > On Mon, Mar 15, 2021 at 06:16:27PM -0700, Li Li wrote: > > To improve the user experience when switching between recently used > > applications, the background applications which are not currently needed > > are cached in the memory. Normally, a well designed application will not > > consume valuable CPU resources in the background. However, it's possible > > some applications are not able or willing to behave as expected, wasting > > energy even after being cached. > > > > It is a good idea to freeze those applications when they're only being > > kept alive for the sake of faster startup and energy saving. These kernel > > patches will provide the necessary infrastructure for user space framework > > to freeze and thaw a cached process, check the current freezing status and > > correctly deal with outstanding binder transactions to frozen processes. I just have some comments on the overall design: This seems a bit convoluted to me; and I'm not sure whether this is really something the kernel should get involved in, or whether this patchset is operating at the right layer. If there are non-binder threads that are misbehaving, could you instead stop all those threads in pure userspace code (e.g. by sending a thread-directed signal to all of them and letting the signal handler sleep on a futex); and if the binder thread receives a transaction that should be handled, wake up those threads again? Or alternatively you could detect that the application is being woken up frequently even though it's supposed to be idle (e.g. using information from procfs), and kill it since you consider it to be misbehaving? Or if there are specific usage patterns you see frequently that you consider to be wasting CPU resources (e.g. setting an interval timer that fires in short intervals), you could try to delay such timers. With your current approach, you're baking the assumption that all IPC goes through binder into the kernel API; things like passing a file descriptor to a pipe through binder or using shared futexes are no longer usable for cross-process communication without making more kernel changes. I'm not sure whether that's a good idea. On top of that, if you freeze a process while it is in the middle of some operation, resources associated with the operation will probably stay in use for quite some time; for example, if an app is in the middle of downloading some data over HTTP, and you freeze it, this may cause the TCP connection to remain active and consume resources for send/receive buffers on both the device and the server.