[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v3 1/6] xen: add reference counter support


  • To: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • From: Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Date: Tue, 11 Apr 2023 22:27:45 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=pkiCktxs4VSNFb5+LI+rK6V+Cf5t5MxyAXN+OKTAnxI=; b=d9OrkvNA6ItuYIfSJOO4TQsKBtkzIdzTYIHbLGWpH0fCO77DNO7W8Teu8rcpl7/uiKtW0+bZg9wGNJz8Ya0aX01Re79UM74AqqqfBe8vlZOPVYucZwEPg5yki6Irx2RBVi1uTuEckze5Db1FChjA89Zf+BYTIGgI9/RFID+zPNoJ695CkgXS7RJkPKoPWYzeUPpChNBL+BNpZeQP+xannzAFCEq2Qhd5AP4vsewcpjs4gNd1ZLy9GJOqo1BxqRsY9ZXwt9j7AMPF6O+m6PIA1RYeihwzRaMrc5hwGUu0Gfmt9TEUL8ZI8nPIloE5c6EPWLasIE6h5pkLIusWFt+95w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KMfA1SKBtkQTIq0hIBTVNbba8WABg5EJ122/OmR8G+fKHrexC6TSLJWYRc2GZhwVt5pxy7M8BzzUhpc6eyyjl9/lxIjPhZj1zwpyoMtEQMQfugF4JSWUIgSP86g0vVGfNuY0KjKZDA4mgdFAiduAGsStgWunX6nMIwBtHIrjV5TTpEorSoHmwxvFwy1TWHzDUQU+Z2qr0b70a/L2RRRX1fSpBO3GT+bCWzfRFKy68I8Rgyz3X1qcKp+/Rgg7stvnAQGyZDL675ebCZECa8GwHdfZw2JxbYwNDkRrfEDcK1RdYDXHFbCvfyxC0PaalgAktbUIg8nZPJpL1dU502gIpw==
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Tue, 11 Apr 2023 22:28:31 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHZVrdyBx9pogLqRUq3RbhGdjZNSK79cEwAgClpiQA=
  • Thread-topic: [PATCH v3 1/6] xen: add reference counter support

Hello Roger,

Sorry for the late answer.

Roger Pau Monné <roger.pau@xxxxxxxxxx> writes:

> On Tue, Mar 14, 2023 at 08:56:29PM +0000, Volodymyr Babchuk wrote:
>> We can use reference counter to ease up object lifetime management.
>> This patch adds very basic support for reference counters. refcnt
>> should be used in the following way:
>> 
>> 1. Protected structure should have refcnt_t field
>> 
>> 2. This field should be initialized with refcnt_init() during object
>> construction.
>> 
>> 3. If code holds a valid pointer to a structure/object it can increase
>> refcount with refcnt_get(). No additional locking is required.
>> 
>> 4. Code should call refcnt_put() before dropping pointer to a
>> protected structure. `destructor` is a call back function that should
>> destruct object and free all resources, including structure protected
>> itself. Destructor will be called if reference counter reaches zero.
>> 
>> 5. If code does not hold a valid pointer to a protected structure it
>> should use other locking mechanism to obtain a pointer. For example,
>> it should lock a list that hold protected objects.
>
> Sorry, I didn't look at the previous versions, but did we consider
> importing refcount_t and related logic from Linux?

Well, I considered this. But it is more complex. It has separate
refcount module, which just counts references + kref code, that is
capable of calling destructors. I am not sure if Xen need this
division. In any case, I tried to replicate Linux behavior as close as
possible. On other hand, Jan suggests to rework API, so it will be
differ from Linux one...

-- 
WBR, Volodymyr

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.