From: Alexander Aring <aahringo@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCHv3 dlm/next 08/20] fs: dlm: simplify writequeue handling
Date: Mon, 4 Jan 2021 16:00:12 -0500 [thread overview]
Message-ID: <20210104210024.233765-9-aahringo@redhat.com> (raw)
In-Reply-To: <20210104210024.233765-1-aahringo@redhat.com>
This patch cleans up the current dlm sending allocator handling by using
some named macros, list functionality and removes some goto statements.
Signed-off-by: Alexander Aring <aahringo@redhat.com>
---
fs/dlm/lowcomms.c | 83 ++++++++++++++++++++++++-----------------------
1 file changed, 43 insertions(+), 40 deletions(-)
diff --git a/fs/dlm/lowcomms.c b/fs/dlm/lowcomms.c
index 02ab939ad8d3..8c826e95493c 100644
--- a/fs/dlm/lowcomms.c
+++ b/fs/dlm/lowcomms.c
@@ -102,6 +102,9 @@ struct listen_connection {
struct work_struct rwork;
};
+#define DLM_WQ_REMAIN_BYTES(e) (PAGE_SIZE - e->end)
+#define DLM_WQ_LENGTH_BYTES(e) (e->end - e->offset)
+
/* An entry waiting to be sent */
struct writequeue_entry {
struct list_head list;
@@ -1332,7 +1335,7 @@ static struct writequeue_entry *new_writequeue_entry(struct connection *con,
{
struct writequeue_entry *entry;
- entry = kmalloc(sizeof(struct writequeue_entry), allocation);
+ entry = kzalloc(sizeof(*entry), allocation);
if (!entry)
return NULL;
@@ -1342,20 +1345,48 @@ static struct writequeue_entry *new_writequeue_entry(struct connection *con,
return NULL;
}
- entry->offset = 0;
- entry->len = 0;
- entry->end = 0;
- entry->users = 0;
entry->con = con;
+ entry->users = 1;
return entry;
}
+static struct writequeue_entry *new_wq_entry(struct connection *con, int len,
+ gfp_t allocation, char **ppc)
+{
+ struct writequeue_entry *e;
+
+ spin_lock(&con->writequeue_lock);
+ if (!list_empty(&con->writequeue)) {
+ e = list_last_entry(&con->writequeue, struct writequeue_entry, list);
+ if (DLM_WQ_REMAIN_BYTES(e) >= len) {
+ *ppc = page_address(e->page) + e->end;
+ e->end += len;
+ e->users++;
+ spin_unlock(&con->writequeue_lock);
+
+ return e;
+ }
+ }
+ spin_unlock(&con->writequeue_lock);
+
+ e = new_writequeue_entry(con, allocation);
+ if (!e)
+ return NULL;
+
+ *ppc = page_address(e->page);
+ e->end += len;
+
+ spin_lock(&con->writequeue_lock);
+ list_add_tail(&e->list, &con->writequeue);
+ spin_unlock(&con->writequeue_lock);
+
+ return e;
+};
+
void *dlm_lowcomms_get_buffer(int nodeid, int len, gfp_t allocation, char **ppc)
{
struct connection *con;
- struct writequeue_entry *e;
- int offset = 0;
if (len > DEFAULT_BUFFER_SIZE ||
len < sizeof(struct dlm_header)) {
@@ -1368,35 +1399,7 @@ void *dlm_lowcomms_get_buffer(int nodeid, int len, gfp_t allocation, char **ppc)
if (!con)
return NULL;
- spin_lock(&con->writequeue_lock);
- e = list_entry(con->writequeue.prev, struct writequeue_entry, list);
- if ((&e->list == &con->writequeue) ||
- (PAGE_SIZE - e->end < len)) {
- e = NULL;
- } else {
- offset = e->end;
- e->end += len;
- e->users++;
- }
- spin_unlock(&con->writequeue_lock);
-
- if (e) {
- got_one:
- *ppc = page_address(e->page) + offset;
- return e;
- }
-
- e = new_writequeue_entry(con, allocation);
- if (e) {
- spin_lock(&con->writequeue_lock);
- offset = e->end;
- e->end += len;
- e->users++;
- list_add_tail(&e->list, &con->writequeue);
- spin_unlock(&con->writequeue_lock);
- goto got_one;
- }
- return NULL;
+ return new_wq_entry(con, len, allocation, ppc);
}
void dlm_lowcomms_commit_buffer(void *mh)
@@ -1409,7 +1412,8 @@ void dlm_lowcomms_commit_buffer(void *mh)
users = --e->users;
if (users)
goto out;
- e->len = e->end - e->offset;
+
+ e->len = DLM_WQ_LENGTH_BYTES(e);
spin_unlock(&con->writequeue_lock);
queue_work(send_workqueue, &con->swork);
@@ -1435,11 +1439,10 @@ static void send_to_sock(struct connection *con)
spin_lock(&con->writequeue_lock);
for (;;) {
- e = list_entry(con->writequeue.next, struct writequeue_entry,
- list);
- if ((struct list_head *) e == &con->writequeue)
+ if (list_empty(&con->writequeue))
break;
+ e = list_first_entry(&con->writequeue, struct writequeue_entry, list);
len = e->len;
offset = e->offset;
BUG_ON(len == 0 && e->users == 0);
--
2.26.2
next prev parent reply other threads:[~2021-01-04 21:00 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-04 21:00 [Cluster-devel] [PATCHv3 dlm/next 00/20] fs: dlm: introduce dlm re-transmission layer Alexander Aring
2021-01-04 21:00 ` [Cluster-devel] [PATCHv3 dlm/next 01/20] fs: dlm: set connected bit after accept Alexander Aring
2021-01-04 21:00 ` [Cluster-devel] [PATCHv3 dlm/next 02/20] fs: dlm: set subclass for othercon sock_mutex Alexander Aring
2021-01-04 21:00 ` [Cluster-devel] [PATCHv3 dlm/next 03/20] fs: dlm: add errno handling to check callback Alexander Aring
2021-01-04 21:00 ` [Cluster-devel] [PATCHv3 dlm/next 04/20] fs: dlm: add check if dlm is currently running Alexander Aring
2021-01-04 21:00 ` [Cluster-devel] [PATCHv3 dlm/next 05/20] fs: dlm: change allocation limits Alexander Aring
2021-01-04 21:00 ` [Cluster-devel] [PATCHv3 dlm/next 06/20] fs: dlm: public header in out utility Alexander Aring
2021-01-04 21:00 ` [Cluster-devel] [PATCHv3 dlm/next 07/20] fs: dlm: use GFP_ZERO for page buffer Alexander Aring
2021-01-04 21:00 ` Alexander Aring [this message]
2021-01-04 21:00 ` [Cluster-devel] [PATCHv3 dlm/next 09/20] fs: dlm: add more midcomms hooks Alexander Aring
2021-01-04 21:00 ` [Cluster-devel] [PATCHv3 dlm/next 10/20] fs: dlm: make buffer handling per msg Alexander Aring
2021-01-04 21:00 ` [Cluster-devel] [PATCHv3 dlm/next 11/20] fs: dlm: make new buffer handling softirq ready Alexander Aring
2021-01-04 21:00 ` [Cluster-devel] [PATCHv3 dlm/next 12/20] fs: dlm: add functionality to re-transmit a message Alexander Aring
2021-01-04 21:00 ` [Cluster-devel] [PATCHv3 dlm/next 13/20] fs: dlm: move out some hash functionality Alexander Aring
2021-01-04 21:00 ` [Cluster-devel] [PATCHv3 dlm/next 14/20] fs: dlm: remove unaligned memory access handling Alexander Aring
2021-01-04 21:00 ` [Cluster-devel] [PATCHv3 dlm/next 15/20] fs: dlm: add union in dlm header for lockspace id Alexander Aring
2021-01-04 21:00 ` [Cluster-devel] [PATCHv3 dlm/next 16/20] fs: dlm: add per node receive flush Alexander Aring
2021-01-04 21:00 ` [Cluster-devel] [PATCHv3 dlm/next 17/20] fs: dlm: add reliable connection if reconnect Alexander Aring
2021-01-04 21:00 ` [Cluster-devel] [PATCHv3 dlm/next 18/20] fs: dlm: don't allow half transmitted messages Alexander Aring
2021-01-04 21:00 ` [Cluster-devel] [PATCHv3 dlm/next 19/20] fs: dlm: remove obsolete code and comment Alexander Aring
2021-01-04 21:00 ` [Cluster-devel] [PATCHv3 dlm/next 20/20] fs: dlm: check for invalid namelen Alexander Aring
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210104210024.233765-9-aahringo@redhat.com \
--to=aahringo@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).